7

I have an activity that has the intent filter android.intent.action.SEND with picture mime types.

Once the user shares the picture (specifically from the downloads manager) with my activity (UploadActivity), the activity will check if the user is logged in. If not, it will store the original intent (with EXTRA_STREAM) and send the user to the LoginActivity. Once that user is logged in, he will be brought back to UploadActivity with the original saved intent.

Now, even after restoring the original intent, I get a java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri....

I understand why I get this. It is because I don't have the temporary permission that the original intent had.

Edit: 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
ademers
  • 967
  • 3
  • 15
  • 24
  • 1
    Please post all of the LogCat errors. To be certain, do you have the `INTERNET` permission? – Sam Mar 05 '13 at 17:40
  • Original post has been updated. Yes I do have the `INTERNET` permission. It is the only permission I have. – ademers Mar 05 '13 at 17:51
  • 1
    @AWebDevDuh : u have also added `android.permission.ACCESS_ALL_DOWNLOADS` permission ? – ρяσѕρєя K Mar 05 '13 at 17:52
  • I forgot to mention. That permission doesn't exists as it's at the signature-level. I don't want to get the Uri on the second instance of the UploadActivity. I just want to do a check on the first instance. – ademers Mar 05 '13 at 17:56
  • 2
    Add permission ` ` – Wei Yang Jul 15 '14 at 22:56

1 Answers1

0

Please post your full Code for querying the ContentProvider. I had a similar issue. when calling a cursor with:

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

however when i set the projection to

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

it works. As soon as i add MediaStore.MediaColumns.MIME_TYPE to the projection, it fails again. It seems to me, that the provider does not grant access to this (and maybe some other) column.

r-hold
  • 941
  • 8
  • 30
  • Well after testing this for a while i am under the impression this is just a first step. With the MediaStore.MediaColumns.MIME_TYPE mimeType i constantly get Exceptions, but without it i still get SecurityExceptions from time to time. Maybe the permission is revoked after some time? The longer i sit in debug mode the more likely an exception on the next query seems to be. For me quering a single Uri from an "ACTION_SEND" semms to work but querying multiple Uris from "ACTION_SEND_MULTIPLE" still causes some troubles from time to time. – r-hold Mar 11 '14 at 09:48
  • I hit the same stumbling block - sometimes I can access the contents stream, at other times I get SecurityException, identical file etc. Did you find out more about this issue? – gregko Sep 30 '14 at 23:20