Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord

java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord

<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 code:

 @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)

This code leads to this question,but I delete this code,this app will crash after installed.

like image 625
skite Avatar asked Jan 20 '26 03:01

skite


1 Answers

Baby~ you cant try this way:

installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK)

I guess need put together , permission allow activity_new_task!

like image 196
巧克力 Avatar answered Jan 22 '26 17:01

巧克力