浏览器网络下载完apk之后需要自动安装
程序员文章站
2022-09-21 09:21:05
前言碰到客户需求:浏览器网络下载完apk之后需要自动安装代码如下(示例):diff --git a/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadScanner.java b/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadScanner.javaindex ca79506....
前言
碰到客户需求:浏览器网络下载完apk之后需要自动安装
代码如下(示例):
diff --git a/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadScanner.java b/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadScanner.java
index ca79506..596dccc 100755
--- a/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadScanner.java
+++ b/packages/providers/DownloadProvider/src/com/android/providers/downloads/DownloadScanner.java
@@ -35,7 +35,8 @@ import com.android.internal.annotations.GuardedBy;
import com.google.common.collect.Maps;
import java.util.HashMap;
-
+import android.content.Intent;
+import java.io.File;
/**
* Manages asynchronous scanning of completed downloads.
*/
@@ -133,6 +134,11 @@ public class DownloadScanner implements MediaScannerConnectionClient {
}
if (req == null) {
Log.w(TAG, "Missing request for path " + path);
+ Intent intent1 = new Intent(Intent.ACTION_VIEW);
+ intent1.setDataAndType(Uri.fromFile(new File(path)),
+ "application/vnd.android.package-archive");
+ intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(intent1);
return;
}
总结
这里只是下载完之后调用安装,如果需要自动安装则需要再打入静默安装补丁。参考补丁:https://blog.csdn.net/sunhao842392744/article/details/109002201
本文地址:https://blog.csdn.net/sunhao842392744/article/details/109002154
上一篇: c语言实现弹跳的小球,弹跳打中砖块消失
下一篇: 事件分发传递过程