When a folder is given permission to read/write a folder and .nomedia file is then added to that folder. The media files are then not accessible to the user. The .nomedia should only hide the media files from the Gallery App or other Apps, not from within the App that has permission to use it.
Steps to reproduce:
- In an App, Select a folder with media in it and give permission to use it.
- View that the media files are readable
- Add a .nomedia file to the folder
- Go back to the App. The media files are no longer visible. Device: Pixel 7 Pro OS: Android 13
LogCat: Permission to access file: /storage/emulated/0/XX/1705.jpg is denied Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/XX/NRCTOPO/03/11E5/1705.jpg: open failed: EACCES (Permission denied)
Does anyone have a workaround for this? .nomedia worked as expected before Storage Access Framework.
Here is the code used for sharing a folder.
// Select the folder using picker
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
);
activity.startActivityForResult(intent, SELECT_FOLDER);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data != null)
{
Bundle extras = data.getExtras();
switch(requestCode) {
case SELECT_FOLDER:
Uri uri = data.getData();
getContentResolver().takePersistableUriPermission(uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
break;
}
}
}