From 1d3895cd3a46eb8e38dafe40b1fc0fe1d913cff7 Mon Sep 17 00:00:00 2001 From: zyzzchehe Date: Sat, 22 May 2021 17:30:48 +0800 Subject: [PATCH] =?UTF-8?q?20210522=20=E6=9B=B4=E6=96=B0=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zc/mylibrary/DownloadApkTask.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/mylibrary/src/main/java/com/zc/mylibrary/DownloadApkTask.java b/mylibrary/src/main/java/com/zc/mylibrary/DownloadApkTask.java index a2d0772..435591a 100644 --- a/mylibrary/src/main/java/com/zc/mylibrary/DownloadApkTask.java +++ b/mylibrary/src/main/java/com/zc/mylibrary/DownloadApkTask.java @@ -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"); @@ -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(); }