Can't handle MediaStore URI if no Storage Permission.
See original GitHub issueIf Storage Permission is not granted, fetchDecodedImage
in ImagePipeline
fails when passed an ImageRequest
with a MediaStore URI (e.g. content://media/external/images/media/917
).
Error is /storage/emulated/0/DCIM/Camera/20161128_142252.jpg: open failed: EACCES (Permission denied)
My workaround was to convert the MediaStore Uri into a File Uri that is saved in the cache directory. The File Uri is then passed to Fresco.
if (UriUtil.isLocalCameraUri(uri)) {
uri = copyMediaStoreUriToCacheDir(uri, filename);
}
Uri copyMediaStoreUriToCacheDir(Uri uri, String filename) {
String destinationFilename = App.getAppContext().getCacheDir().getAbsolutePath() + "/" + filename;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(App.getAppContext().getContentResolver().openInputStream(uri));
bos = new BufferedOutputStream(new FileOutputStream(destinationFilename, false));
byte[] buf = new byte[1024];
bis.read(buf);
do {
bos.write(buf);
} while (bis.read(buf) != -1);
return Uri.fromFile(new File(destinationFilename));
} catch (IOException e) {
//
} finally {
try {
if (bis != null) {
bis.close();
}
if (bos != null) {
bos.close();
}
} catch (IOException e) {
//
}
}
return null;
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Access media files from shared storage | Android Developers
If scoped storage is enabled, the collection shows only the photos, videos, and audio files that your app has created. Most developers won't...
Read more >How to get permanent access to file URI [duplicate]
the error I get: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.
Read more >Scoped Storage Stories: More on ... - CommonsWare
The biggest problem is that RecoverableSecurityException is on a per- Uri basis. The exception contains an IntentSender that can be used to get ......
Read more >Working with Scoped Storage - ProAndroidDev
In a nutshell, Scoped Storage prevents apps from having unrestricted access to the filesystem on the device . Previously, an app could access...
Read more >storage permission in android 11 | read & write both - YouTube
Hello everyoneIn this video i will teach you how to take storage persmission in android 11 for both read & write operation.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@oprisnik: Sorry. Another thing I left out is it only happens in certain devices like LG G4 and Samsung Galaxy S6 - 6.0.1.
Same code in my Google Pixel works fine.
Thanks, I only tested
ACTION_OPEN_DOCUMENT
andACTION_PICK
(sample will be available soon). I’ll test withACTION_GET_CONTENT
.