在我的Android应用程序中,我正在尝试为用户提供一个工具,从他们的Google相册中选择照片并上传到应用程序。当我从Google照片中检索Uri
并使用检索到的imageview
在uri
中显示该图像时,该功能很有效。但是,当我使用相同的uri将图像上传到Firebase存储时,应用程序崩溃在以下代码行:
UploadTask uploadTaskPic = picReference.putFile(picUriLocal);
picUriLocal
是我从Google照片中收到的Uri。下面给出错误的Stacktrace:
12-17 11:31:41.814 18971-18971/me.buddy.buddy E/AndroidRuntime:
FATAL EXCEPTION: main
Process: me.buddy.buddy, PID: 18971
java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.impl.MediaContentProvider from
ProcessRecord{27fa910 18971:me.buddy.buddy/u0a154} (pid=18971, uid=10154) that is not exported from uid 10057 at android.os.Parcel.readException(Parcel.java:1629) at android.os.Parcel.readException(Parcel.java:1582)
atandroid.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3598)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:5172)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2026)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1481)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1101)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:955) at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:808)at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:762)
at com.google.firebase.storage.UploadTask.<init>(Unknown Source)
at com.google.firebase.storage.StorageReference.putFile(Unknown Source)
at me.buddy.buddy.ui.UserProfile.saveAndClose(UserProfile.java:211)
at me.buddy.buddy.ui.UserProfile.access$000(UserProfile.java:68)
at me.buddy.buddy.ui.UserProfile$1.onClick(UserProfile.java:97)
at android.view.View.performClick(View.java:5232)
at android.view.View$PerformClick.run(View.java:21289)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
在UploadTask
的文档中,它声明:
uri:
The source of the upload. This can be a file:// scheme or any content URI. A content resolver will be used to load the data.
所以我无法找出安全例外的原因。
答案 0 :(得分:0)
由于内容解析程序问题,此安全例外正在发生。 GooglePhotos
正在返回上述代码无法读取的"content://"
uri,特别是UploadTask
。所以我将googlePhotos中的图像加载到imageview
。我从这张图片的位图创建了一个本地file://
uri。它解决了安全异常。如果答案不够清楚,请随意添加评论。