4
Caused by java.lang.SecurityException: Permission Denial: opening provider com.estrongs.android.pop.app.FileContentProvider from ProcessRecord{341eeb8 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已经实现

4

1 回答 1

2

似乎问题出在 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;
}
于 2019-02-13T07:54:40.460 回答