Android 14 - partial access to photos - how to show only "Allow all" option

1.8k Views Asked by At

My app downloads pictures and saves them in Download/MyAppName folder. There is an Activity in the app that will scan the folder and get all the photos saved in there and show them in a RecyclerView. However the photos will not show in the phone's gallery app by default unless you open them by browsing the Download folder through a File Explorer app. In that case, the photos that you open will show in the phone's gallery app.

The permissions the app asks in Android 13 and 14 is Manifest.permission.READ_MEDIA_IMAGES

The problem is in Android 14 when the user does a "Clear Storage" from the settings or manually revokes the permissions.

So here is the scenario. You use the app and you download say 5 photos. If you revoke the Manifest.permission.READ_MEDIA_IMAGES permission in Android 14, the next time you try to open the app it will ask to grant the permission. But, if the user chooses the option Select photos and videos it will show the photos that are visible to the gallery, which means the photos that were downloaded from the app and where saved in Download/MyAppName folder will not be shown.

So this situation is causing a problem because when the folder is scanned using MediaStore api it means the user will not be able to see the photos previously downloaded from the app unless he chooses Allow all when being asked for permissions.

Is there any way how to force the app only showing the option Allow all and removing Select photos and videos option, just like it is in Android 13?

EDIT (Answering the questions asked in the comments sections)

  1. How the app downloads the files and saves them in Download/MyAppName ?

The app is using Glide to get the bitmap of the remote image. Having the bitmap it is then used to create the file in the given destination as in : bitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(destinationFile));

  1. Why the downloaded photos are not showing up in the Gallery?

Because the app is not using MediaStore api to create the file. You will have to browse the picture using a File Browser app and open them. Only after this is done then the photos will appear in the Gallery.

  1. Why the app needs Manifest.permission.READ_MEDIA_IMAGES permission?

Since the app is not relying on MediaStore api it needs this permission to even access even its own created files.

  1. Why the user is seeing the option Select photos and videos in the permission requester dialog?

Because that's how Android 14 behaves if you try to ask for Manifest.permission.READ_MEDIA_IMAGES. In Android 13 and below it will show only the options of Allow all and Don't allow. When clicking on Allow all the system will grant permission for all the images saved in the external storage. This is same for Android 14 too but if the user clicks on Select photos and videos instead then the things will get complicated.

So, basically the original problem here is that the app is not using MediaStore to handle the creation of the photos. Even if we migrate to MediaStore now and do the things in the right way, still we would need a solution for backward compatibility. I was thinking that instead of asking user for Manifest.permission.READ_MEDIA_IMAGES we ask for Manifest.permission.MANAGE_EXTERNAL_STORAGE but not sure if the app will be accepted in Play Store because it doesn't really qualify in any of these categories.

0

There are 0 best solutions below