Skip to content

Commit

Permalink
20210522 更新安装逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
zyzzchehe committed May 22, 2021
1 parent 7d122b8 commit 1d3895c
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions mylibrary/src/main/java/com/zc/mylibrary/DownloadApkTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected void onPostExecute(String s) {
File apkFile = new File(s);
try {
//兼容7.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
/*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileProvider", apkFile);
intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
Expand All @@ -189,7 +189,37 @@ protected void onPostExecute(String s) {
}
if (context.getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
context.startActivity(intent);
}
}*/
new Thread() {
public void run() {
Process process;
InputStream in = null;
try {
process = Runtime.getRuntime().exec("pm install -r " + s + "\n");
in = process.getInputStream();
int len;
byte[] bs = new byte[256];
while (-1 != (len = in.read(bs))) {
String state = new String(bs, 0, len);
Log.i(TAG, "run: install state = "+state);
if (state.equals("Success\n")) {
Log.i(TAG, "run: install ok");
}
}
apkFile.delete();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.start();
} catch (Throwable e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 1d3895c

Please sign in to comment.