Edit: This is not a duplicate question. No question I've seen answers how to solve this when you don't have control over the activity sending the intent (in my case, a browser app or maybe a file-browsing app is sending the intent to my app). And then more specifically, this is not dealing with photos/gallery.
This has been plaguing an app of mine for a while. I can't personally get it to happen with any device, but I can see from crashes it happens a lot to others.
My app receives an intent containing a ZIP file from an outside app. I catch it in either onCreate()
or onNewIntent()
:
Intent intent = getIntent();
if (intent != null && intent.getData() != null)
beginZipIntent(intent);
In beginZipIntent()
:
Uri data = intent.getData();
String filename = data.toString();
// Open input stream to copy ZIP to a temporary directory.
Uri uri = Uri.parse(filename);
InputStream inputStream = null;
try
{
inputStream = getContentResolver().openInputStream(uri); // This fails
}
catch (Exception e)
{
//...
}
On the line above, some devices fail:
Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider uri content://com.android.providers.downloads.documents/document/2772 from pid=26094, uid=10094 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
I have no control over the app/activity sending the intent. I thought by grabbing the file immediately and saving it to a temporary directory I could remedy this (as seen in other answers) - but nope.
I've also added android.permission.MANAGE_DOCUMENTS
but as expected (from other answers) it doesn't work.
Anyone ever run into this? Seems to affect devices ranging from Android 4 to 7 so not specific to one OS version.