欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

浏览器网络下载完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