I am implementing a system where I take a picture, show it to the user, and upload it. For reasons beyond the scope of this question, I have three apps involved: the system's camera app, my app that shows the UI, and a third app that handles the upload. I own all three apps and can deploy code changes to each.
The problem is that the upload Service (in the third app) doesn't always have access to the content URI and sometimes fails with a SecurityException: Permission Denial.
This is what I do:
- The UI app requests a picture be taken by the Camera app
- The Camera app starts, takes a picture, and returns the result back to the UI app with a URI and the
FLAG_GRANT_READ_URI_PERMISSIONflag in theIntent - The UI app receives the result, has permission to access the URI, loads/displays the picture taken in an
ImageView - Upon user click, my app binds to the Service in the third app and attempts to grant URI permission/access to the service by setting the URI in the
dataproperty of theIntentpassed intobindServiceand setting theFLAG_GRANT_READ_URI_PERMISSION - My
Activitythen finishes itself - The Service app service is started and bound to, it receives the URI to upload and, sometimes, fails with a
SecurityException
My questions are:
- Is it even possible to forward URI permission access from a component in one app (my Activity) to another component in another app (the upload Service)?
- Same question, but what if the component in the other app is a bound service and not a started service, do I use the
Intentpassed into thebindServicecall to do this? What if the service is already running from before? - Since
FLAG_GRANT_READ_URI_PERMISSIONis designed to automatically revoke permissions once the life-cycle ends, does that mean that the access granted from theActivityto the boundServiceis revoked once theActivityis finished even though the lifespan of aServiceshould be longer by design?