java.lang.SecurityException:权限拒绝:从 ProcessRecord 打开提供程序 android.support.v4.content.FileProvider

ski*_*ite 3 installation android

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>
Run Code Online (Sandbox Code Playgroud)

代码:

 @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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

这段代码导致了这个问题,但我删除了这段代码,这个应用程序安装后会崩溃。

小智 5

宝贝~你不能这样试:

installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK)
Run Code Online (Sandbox Code Playgroud)

我想需要放在一起,权限允许activity_new_task!