java.lang.SecurityException:权限拒绝:打开提供程序 com.estrongs.android.pop.app.FileContentProvider

Posted

技术标签:

【中文标题】java.lang.SecurityException:权限拒绝:打开提供程序 com.estrongs.android.pop.app.FileContentProvider【英文标题】:java.lang.SecurityException: Permission Denial: opening provider com.estrongs.android.pop.app.FileContentProvider 【发布时间】:2019-07-02 10:16:56 【问题描述】:
Caused by java.lang.SecurityException: Permission Denial: opening provider com.estrongs.android.pop.app.FileContentProvider from ProcessRecord341eeb8 5431:xx.xxxx.xxxx/u0a289 (pid=5431, uid=10289) that is not exported from uid 10188
       at android.os.Parcel.readException(Parcel.java:1686)
       at android.os.Parcel.readException(Parcel.java:1639)
       at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4199)
       at android.app.ActivityThread.acquireProvider(ActivityThread.java:5548)
       at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2283)
       at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1517)
       at android.content.ContentResolver.query(ContentResolver.java:516)
       at android.content.ContentResolver.query(ContentResolver.java:474)
       at org.chromium.base.ContentUriUtils.getDisplayName(ContentUriUtils.java:181)
       at org.chromium.android_webview.AwWebContentsDelegateAdapter$GetDisplayNameTask.doInBackground(AwWebContentsDelegateAdapter.java:2374)
       at android.os.AsyncTask$2.call(AsyncTask.java:305)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)

打开文件选择器的代码

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.startActivityForResult(Intent.createChooser(intent, "Open CSV"), READ_REQUEST_CODE);

重现问题的步骤

1) 打开图库以选择照片

2) 从幻灯片菜单中选择ES File Explore

3) 现在一些文件 URI 工作并且一些文件崩溃了

注意:-FileProvider 已经实现

【问题讨论】:

【参考方案1】:

看来问题出在 Nougat(7.1.1) nexus(tested!)

解决方法

从您的代码调用 getFilePathFromUri(this, uri)

public static String getFilePathFromUri(Context context, Uri _uri) 
    String filePath = "";
    if (_uri != null && "content".equals(_uri.getScheme())) 
        //Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
        //context.revokeUriPermission(_uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Cursor cursor = null;
        try 
            cursor = context.getContentResolver().query(_uri,
                    new String[]
                            
                                    MediaStore.Images.ImageColumns.DATA,
                                    MediaStore.Images.Media.DATA,
                                    MediaStore.Images.Media.MIME_TYPE,
                                    MediaStore.Video.VideoColumns.DATA,
                            , null, null, null);
            cursor.moveToFirst();
            filePath = cursor.getString(0);
         catch (SecurityException e) 
            //if file open with third party application
            if (_uri.toString().contains("/storage/emulated/0")) 
                filePath = "/storage/emulated/0" + _uri.toString().split("/storage/emulated/0")[1];
            
         finally 
            if (cursor != null)
                cursor.close();
        

     else 
        filePath = _uri.getPath();
    
    return filePath;

【讨论】:

请检查问题中提到的异常。并检查上述步骤中提到的第 3 点(文件最有可能无法正常工作 VIDEOS 或 DOCS)。

以上是关于java.lang.SecurityException:权限拒绝:打开提供程序 com.estrongs.android.pop.app.FileContentProvider的主要内容,如果未能解决你的问题,请参考以下文章