java.lang.SecurityException: 权限拒绝:从ProcessRecord打开提供程序android.support.v4.content.FileProvider。
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="cn.cloudworkshop.miaoding.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"
tools:replace="android:resource"/>
</provider>
Java代码:
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
Intent install = new Intent(Intent.ACTION_VIEW);
Uri contentUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
contentUri = FileProvider.getUriForFile(context, "cn.cloudworkshop.miaoding.fileprovider", file);
} else {
contentUri = Uri.fromFile(file);
}
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
install.setDataAndType(contentUri, "application/vnd.android.package-archive");
context.startActivity(install);
}
}
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
这段代码会导致这样一个问题,如果我删除这段代码,安装后的应用程序将崩溃。