app/src/main/AndroidManifest.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
app/src/main/java/com/hdl/photovoltaic/widget/apkwgtupload/AppDownloadManager.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
app/src/main/res/xml/provider_paths.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
app/src/main/AndroidManifest.xml
@@ -124,6 +124,7 @@ <activity android:name=".ui.HomeLoginActivity" android:exported="false" /> <activity android:name=".widget.apkwgtupload.AndroidPermissionActivity" /> <activity android:name=".ui.StartActivity" android:exported="true"> @@ -135,6 +136,18 @@ </activity> <!-- 注册服务 --> <service android:name=".internet.HttpServer.MyNanoHttpService" /> <provider android:name="androidx.core.content.FileProvider" android:authorities="com.hdl.photovoltaic.fileProvider" android:exported="false" android:grantUriPermissions="true" tools:replace="android:authorities"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" tools:replace="android:resource" /> </provider> <meta-data android:name="design_height_in_dp" android:value="812" /> app/src/main/java/com/hdl/photovoltaic/widget/apkwgtupload/AppDownloadManager.java
@@ -110,8 +110,11 @@ //设置监听Uri.parse("content://downloads/my_downloads") weakReference.get().getContentResolver().registerContentObserver(Uri.parse("content://downloads/my_downloads"), true, mDownLoadChangeObserver); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE); // 注册广播,监听APK是否下载完成 weakReference.get().registerReceiver(mDownloadReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); weakReference.get().registerReceiver(mDownloadReceiver, intentFilter); } /** @@ -148,7 +151,8 @@ downSuccess = true; Log.i(TAG, "下载进度:完成"); } Log.i(TAG, "下载进度:" + bytesAndStatus[0] + "/" + bytesAndStatus[1] + ""); long value = bytesAndStatus[0]* 100L / bytesAndStatus[1]; Log.i(TAG, "下载进度:" + value + ""); } class DownloadChangeObserver extends ContentObserver { @@ -245,7 +249,7 @@ uri = Uri.fromFile(apkFile); } else { // Android 7.0 以上 uri = FileProvider.getUriForFile(context, "com.hdl.debugtreasure.dc.fileprovider", "com.hdl.photovoltaic.fileProvider", new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), HdlAppUpdateLogic.getInstance().getApkFileName())); intentInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } app/src/main/res/xml/provider_paths.xml
New file @@ -0,0 +1,9 @@ <?xml version="1.0" encoding="utf-8"?> <paths> <external-path name="external" path="" /> <external-files-path name="Download" path="" /> </paths>