Photo Picker with READ_MEDIA_VISUAL_USER_SELECTED permission on Android 14 still shows all media content – Android

by
Maya Patel
android android-14 android-permissions

Quick Fix: Keep using the File class to list files, but it will only list the files the user has selected with READ_MEDIA_VISUAL_USER_SELECTED.

The Problem:

In Android 14, the Photo Picker with READ_MEDIA_VISUAL_USER_SELECTED permission still displays all media content instead of only displaying media content that has been granted permission.

The Solutions:

Solution 1: READ_MEDIA_VISUAL_USER_SELECTED permission has nothing to do with Intent.ACTION_GET_CONTENT, Intent.ACTION_PICK_IMAGES or ActivityResultContracts.PickVisualMedia, but with File.listFiles() method.

The documentation is not clear enough and there is a lot of confusion around it. It seems that the READ_MEDIA_VISUAL_USER_SELECTED permission has nothing to do with the PhotoPicker or the new photo picker dialog, but with the classic File class.

If your app requests the READ_MEDIA_IMAGES permission and the user confirms, then your app can use the File class to list files in, for example, the DCIM/Camera directory, and see all files of the default Camera app. This is true for Android 14 too.

But if you request READ_MEDIA_IMAGES and READ_MEDIA_VISUAL_USER_SELECTED, and the user selects four files in DCIM/Camera, then after that the File.listFiles() function will only list those four files, even if you are using the Intent-based photo picker, File.listFiles() is not aware of the new partial access.

Q&A

Photo Picker with READ_MEDIA_VISUAL_USER_SELECTED permission still shows all media content.

New permission READ_MEDIA_VISUAL_USER_SELECTED not related to PickVisualMedia, File.listFiles function only lists user-selected files.

READ_MEDIA_VISUAL_USER_SELECTED – Classic File class behavior change in Android 14?

If app requests READ_MEDIA_VISUAL_USER_SELECTED, File.listFiles only lists user-selected files.

READ_MEDIA_VISUAL_USER_SELECTED permission on Android 14 with Photo Picker?

Using the Photo Picker alone does not require READ_MEDIA_VISUAL_USER_SELECTED permission.