Android Developers
Published in

Android Developers

Permissionless is the future of Storage on Android

Whether it’s to change a profile avatar, share vacation pictures, or add an attachment to an email, selecting and sharing media files are one of the most common things users do on mobile apps. After listening to feedback from Android users, we’ve made a few changes to how apps access media files. And based on what we’ve learned from talking to developers, we’ve introduced a helpful new tool.

At Android, we believe asking users to select photos and videos should be helpful, easy to implement, and privacy conscious.

Deprecation of existing storage permissions

Many users told us that the Files & Media permission bothers them, because they don’t know which files the app wants access to.

On Android 13, we’re deprecating READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions in favour of better alternative APIs for media file access.

Keep in mind that you don’t need any permission to add files to shared storage from Android 10. So if your app only adds files in the shared storage, you can stop requesting any permission on Android 10+

Historically, apps requested READ_EXTERNAL_STORAGE to ask users to grant access to Files & Media. Then, they implemented their own media picking experience, adding heavy development & maintenance costs to the developer team. Alternatively, apps relied on the system file picker through ACTION_GET_CONTENT or ACTION_OPEN_CONTENT, but we’ve heard from developers that it didn’t feel well-integrated to their apps UX:

System File Picker using ACTION_OPEN_CONTENT
System File Picker using ACTION_OPEN_CONTENT

Introducing the photo picker

In Android 13, we introduced a new visual media picking tool: the Android photo picker. This tool provides a way for users to select media files, without needing to grant access to their entire media library.

It provides a clean, browsable interface that presents the user with their photos and videos, sorted by date. In addition the “Albums” section lets users browse by helpful categories like Screenshots or Downloads. The photo picker is customisable by specifying if users should see only photos or only videos, or by setting a maximum number of items they can select. In short, this solution is private by design, has a clean and integrated UX & is easy to implement.

We’ve also backported the photo picker on Android 11 & 12* through a Google Play system update (1 May 2022 release) to bring it to a wider Android audience.

While building your own media picker is a complex and laborious project to develop and update, the photo picker doesn’t require any maintenance from your team. It’s a simple intent to be launched and we’ve already created an ActivityResultContract for it in the ActivityX 1.6.0 release. It will use the photo picker when available and fallback to ACTION_OPEN_DOCUMENT on older devices:

// Registering Photo Picker activity launcher with a max limit of 5 items
val pickMultipleVisualMedia = registerForActivityResult(PickMultipleVisualMedia(5)) { uris ->
// TODO: process URIs
}
// Launching the photo picker (photos & video included)
pickMultipleVisualMedia.launch(PickVisualMediaRequest(PickVisualMedia.ImageAndVideo))

If you’re looking to add a type filtering, you can do it this way:

// Launching the photo picker (photos only)
pickMultipleVisualMedia.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly))
// Launching the photo picker (video only)
pickMultipleVisualMedia.launch(PickVisualMediaRequest(PickVisualMedia.VideoOnly))
// Launching the photo picker (GIF only)
pickMultipleVisualMedia.launch(PickVisualMediaRequest(PickVisualMedia.SingleMimeType("image/gif")))

You can verify whether the photo picker is available on a given device by calling isPhotoPickerAvailable.

Check out the documentation for more details on adding the photo picker to your application.

ACTION_GET_CONTENT behaviour change

As we just saw, adopting the Android photo picker requires just a few lines of code. While we want all apps to use it, migration might take some time in your app. That’s why we are bringing the benefits of Android photo picker to existing apps using ACTION_GET_CONTENT by switching the system file picker for the photo picker under the hood without any code change required in the upcoming months. If you launch the ACTION_GET_CONTENT intent with an image and/or video mime type filter, the photo picker will be shown instead of the document picker. For applications, the expected intent results will be the same: a list of Uri.

ACTION_GET_CONTENT will open the photo picker instead of the document picker

New permissions for specific use cases

While we strongly recommend you to use the new photo picker over requesting access to all media files, your app may have a use case requiring this broad access (e.g. gallery photo backup). For these specific usages, we’re introducing new permissions that provide access to specific types of media files, including images, video, or audio. You can read more about them in the documentation.

If the user previously granted your app the READ_EXTERNAL_STORAGE permission, the system automatically grants the granular media permissions to your app. Otherwise, the system shows a user-facing dialog when your app requests any of the new permissions.

Keep in mind that you must always check if any permissions are still granted rather than storing their grant states. With app hibernation and expiring permission grants

Check out this decision tree to help you navigate through these changes:

With these announcements, we’re committed to keep improving the photo picker and overall storage developer experience while protecting user privacy to create a secure and transparent Android ecosystem. If you have any feedback or suggestions, submit tickets to our issue tracker!

*: The Android photo picker is backported to all Android 11 & 12 devices, excluding Android Go and non-GMS devices.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yacine Rezgui

🇫🇷🇹🇳 Developer Relations Engineer 🥑 on Android working on privacy @Google in London. Hacking projects on free time