1

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;
        }
    }
}
  • If you are using the Storage Access Framework, you would be accessing files via Uris, nor via file paths as your error indicates you are trying to do. Uri access is not impacted by the presence of a `.nomedia` file in a directory, so please show your code. – ianhanniballake Jun 10 '23 at 14:41
  • `In an App, Select a folder with media in it and give permission to use it.` ??? In which app? How does one select a folder? With what? How can one give a use permission? All pretty unclear. – blackapps Jun 10 '23 at 14:45
  • In short: pretty unclear where this is about. Please rewrite your post and show used code. – blackapps Jun 10 '23 at 14:49
  • ianhanniballake: When a user gives permission to use a folder, then you can access the files using legacy file references and functions. @blackapps: The App, I mean my App. .nomedia does in fact affect the visibility of the files in a folder. You can test this out by creating a .nomedia file in a folder with media in it. When you go to the Gallery App or use PickVisualMediaRequest, those photos will no longer be visible. – MuskokaGeek Jun 11 '23 at 21:27
  • Which Gallery app? There are thausands. Google Fotos does not consider it. – blackapps Jun 11 '23 at 21:37
  • @blackapps The default Gallery App on Samsung is an example. The best case is to use PickVisualMediaRequest. This will honor the .nomedia file. – MuskokaGeek Jun 12 '23 at 00:41

0 Answers0