I am trying to get image from third party app (e.g WhatsApp) to my app (being tested on Marshmallow). When I do "share image" from WhatsApp and share it with my app, I get URI something like this:
content://com.whatsapp.provider.media/item/61025
But in my app when I call getContentResolver().openInputStream(uri)
or getContentResolver().openFileDescriptor(uri, "r")
with above URI, it crashes with exception:
java.lang.SecurityException: Permission Denial: opening provider com.whatsapp.MediaProvider from ProcessRecord{a4b804a 30321:com.myapp/u0a145} (pid=30321, uid=10145) that is not exported from uid 10083
What I tried so far
I looked for this exception on SO and found similar question posed but to import images from Google Photos and got that need to add permission like:
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS"/>
But not convienced with this because there could be many apps and need to add permission for each of them or what.
In some other answers it has been suggested to read/copy the data from content provider immediately. But not sure how. Because I get exception in openInputStream
itself.
I also must mention that WhatsApp image can be successfully shared with other apps (e.g. Google Drive) so there must be some way to do this.
Please someone can give share hints or working solution on this?