I am trying to get an image from a third-party application (e.g. WhatsApp) into my application (tested on Marshmallow). When I do "share image" with WhatsApp and share it with my application, I get a URI something like this:
content:
But in my application, when I call getContentResolver().openInputStream(uri)
or getContentResolver().openFileDescriptor(uri, "r")
with the above URI, it crashes out:
java.lang.SecurityException: permission denied: opening provider com.whatsapp.MediaProvider from ProcessRecord {a4b804a 30321: com.myapp / u0a145} (pid = 30321, uid = 10145), which is not exported from uid 10083
What have i tried so far
I looked for this exception in SO and found a similar question , but I imported images from Google Photos and got the need to add permission, for example:
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS"/>
But I do not agree with this, because there can be many applications and you need to add permissions for each of them or what.
Some other answers suggested reading / copying data from the content provider immediately. But I don’t know how to do it. Because I get an exception in myself openInputStream
.
I should also mention that the WhatsApp image can be successfully exchanged with other applications (e.g. Google Drive), so there must be some way to do this.
Please can anyone give a hint or working solution on this?