7

我有一个android.intent.action.SEND带有图片 mime 类型的意图过滤器的活动。

一旦用户与我的活动(UploadActivity)分享图片(特别是来自下载管理器),活动将检查用户是否登录。如果没有,它将存储原始意图(带有EXTRA_STREAM)并将用户发送到 LoginActivity . 一旦该用户登录,他将被带回 UploadActivity 并使用原始保存的意图。

现在,即使在恢复了原始意图之后,我也得到了一个java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri....

我明白我为什么会得到这个。因为我没有原意的临时权限。

编辑:LogCat

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.UploadActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/1145 from pid=16585, uid=10086 requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    at android.app.ActivityThread.access$600(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/1145 from pid=16585, uid=10086 requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
    at android.content.ContentResolver.query(ContentResolver.java:372)
    at android.content.ContentResolver.query(ContentResolver.java:315)
    at com.example.UploadActivity.getFileFromContentUri(UploadActivity.java:304)
    at com.example.UploadActivity.onCreate(UploadActivity.java:195)
    at android.app.Activity.performCreate(Activity.java:5104)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    ... 11 more
4

1 回答 1

0

请发布您查询 ContentProvider 的完整代码。我有一个类似的问题。调用游标时:

c=MyApplication.getAppContext().getContentResolver().query(uri,null,null,null,null);

但是,当我将投影设置为

String[] proj=new String[] {
                MediaStore.MediaColumns.DATA,
                MediaStore.MediaColumns.DISPLAY_NAME,
        }; 
c=MyApplication.getAppContext().getContentResolver().query(uri,proj,null,null,null);

有用。一旦我添加MediaStore.MediaColumns.MIME_TYPE到投影中,它就会再次失败。在我看来,提供者不授予访问此(可能还有其他)列的权限。

于 2014-03-10T12:34:30.333 回答