'Permission error when trying to pass Content Uri from activity to service
I have an activity which accepts android.intent.action.SEND.
It accepts some media files and texts.
As it accepts a new 'share' it does some validation checks and pass the Uri to a service, it looks like this:
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
Intent serviceIntent = new Intent(this, ShareService.class)
.setData(uri)
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // probably redundant but harmless here
.putParcelableArrayListExtra(Constants.EXTRA_SHARE_FILES, uris)
startService(serviceIntent);
It works for all file providers and usually for content as well, but from time to time I get reports of failures:
Non-fatal Exception: java.lang.SecurityException: UID 10283 does not have permission to content://com.whatsapp.provider.media/item/33560 [user 0]
Is there anything I can do to keep the Uri permission alive? how should I handle this kind of Uri?
Solution 1:[1]
please create xml folder in your app and in xml mentioned file provider file and network security configure file after that declare fileprovider in AndroidMenifest.xml file
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JayShah3110 |
