I've got a SendActivity, that launches an UploadService.
The problem happens when i let the SendActivity then immediately starts another activity and finishes itself. The UploadService gets the file, that it's supposed to upload, from a content provider. But when the SendActivity isn't i the foreground in the moment the service tries to access the file through the provider I get a "Permission Denial" although the permission is listed in my manifest.
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaDocumentsProvider uri content://com.android.providers.media.documents/document/image%3A24669 from pid=28913, uid=10441 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:646)
Can anybody help me out?
My guess is that you are passing a Uri
from SendActivity
to UploadService
. SendActivity
perhaps has rights to read that content, but UploadService
does not.
In the Intent
used to start UploadService
, call addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
to transfer read access from SendActivity
to UploadService
, and see if that helps. If it does not, then perhaps SendActivity
also does not have read access, in which case you would need to look at how you are getting the Uri
in the first place.