Exploring Photo Picker in Android 13

Nikit Bhandari
ProAndroidDev
Published in
3 min readFeb 14, 2022
Image credits: https://developer.android.com/

Google recently announced the first Developer Preview of Android 13, while there are a lot of new APIs, the Photo picker excited me a lot both as a user and a developer.

If you want to try the Android 13 APIs, you can follow the instructions mentioned in the documentation. Although if you follow the documentation word by word you will not be able to compile the project, the documentation recommends adding the following code snippet in your build.gradle to set up the SDK.

But at the time of writing this article, you will get the following error:

Unsupported value: Tiramisu. Format must be one of:
- android-31
- android-31-ext2
- android-T
- vendorName:addonName:31

The fix is to use compileSdkPreview and targetSdkPreview instead like it is done in the code snippet below:

Now you should be able to work with the Android 13 SDK 😃

What’s a Photo picker?

Photo picker provides you a new way to select media files stored in your device and cloud using an intent.

You may be thinking, isn’t there already an intent to open the Gallery? Yes, the Photo picker is similar to that in terms of functionality and it comes with a new refreshed UI.

Let’s have a look at the existing way of opening a Gallery through an intent

The following GIF shows how this intent would open up your Gallery

Now let’s see how to use the Photo picker in Android 13

This code snippet would open up a dialog from the bottom and allow the user to select an image from the Gallery.

If you want to select multiple images you can provide the maximum number of images using EXTRA_PICK_IMAGES_MAX extra

The maximum value that we are using in the above code snippet can be any positive integer greater than 1 and less than or equal to the value returned from MediaStore.getPickImagesMaxLimit()

Now the dialog would open up in full screen and you also have the option to view the selected images in a preview.

You can also provide the media type, in case you want the user to select only videos or images

At the time of writing this article, if you use the above intent, all your videos would be listed under the photos tab as you can see in the screenshot below (Hopefully this will get fixed soon)

While using these intents to select media files, you can retrieve the URI of the media file in onActivityResult, you will either get a single URI or a list of URIs depending on the type of intent you have used.

I like the new Photo picker and since it is a dialog that pops up in an app, it feels that you are still in the app while selecting an image/video. I feel its name is a little confusing since you can use the Photo picker to select a video as well, I guess Media picker would be less confusing but naming is hard so let’s not get into it 😛 Let me know what to do you think about the Photo picker.

If you have feedback, feel free to tweet or message me on Twitter.

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Responses (2)

What are your thoughts?

startActivityForResult is deprecated, ActivityResultContracts.StartActivityForResult must be used instead.

--

This looks fine for the case that I want to share a very recent photo but thats often not the case for me. For that I like to open a full blown file manager where I can find my photos by searchin the correct hierarchy and folders. This is way faster than scrolling for ever til I reach it.

--