This commit is contained in:
Jerry Yan 2020-02-27 21:26:03 +08:00
parent aecaa6e1e3
commit 60760914f6
3 changed files with 24 additions and 1 deletions

View File

@ -9,5 +9,15 @@
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</receiver>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<!-- 元数据 -->
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/j_rn_a_vu_file_path" />
</provider>
</application>
</manifest>

View File

@ -39,7 +39,14 @@ public class DownLoadBroadcastReceiver extends BroadcastReceiver {
}
if(filePath == null) return;
File file = new File(filePath);
Log.e("PATH", String.valueOf(Uri.parse(file.getAbsolutePath())));
Log.e("PATH", String.valueOf(Uri.fromFile(file)));
if (Build.VERSION.SDK_INT >= 24) {
Uri apkUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + "" + ".fileprovider", file);
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.setDataAndType(apkUri, "application/vnd.android.package-archive");
} else {
install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
}
install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(install);

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<paths>
<external-path path="" name="download" />
</paths>
</resources>