android - 来自 ProcessRecord 的 java.lang.SecurityException : Permission Denial: opening provider android. support.v4.content.FileProvider

标签 android installation

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代码:

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

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

最佳答案

宝贝~你不能这样试:

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

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

关于android - 来自 ProcessRecord 的 java.lang.SecurityException : Permission Denial: opening provider android. support.v4.content.FileProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44712545/

相关文章:

android - android 中的 SQLite 数据库

android - 如何在 fragment 中使用 Retrofit 和 Loader 类

android - 更改解析后出现的微调项的文本颜色

java - getResourceAsStream() 返回 null

MySQL 在 Mac 上无法启动,即使它是使用 Brew 安装的

.net - 创建 .NET Windows 服务安装程序的最佳方法是什么?

android - 使用许多位图时出现内存不足错误

c# - 使用 mysql c# 创建安装程序包

testing - 构建具有最小依赖性的 couchdb

bash - Homebrew 软件 NoMethodError:OS::Mac:Module 的未定义方法 `prefer_64_bit?'