Exploring Android 13: Photo Picker

M Farhan Majid
3 min readFeb 24, 2022

--

Android 13 (Tiramisu)’s new APIs and features are ready to be tried out by developers. One of the new features offered in this phase is the new Photo Picker.

As the name clearly suggests, Photo Picker is a method for picking media files (images and/or videos). Android 13’s new Photo Picker offers several benefits to users and developers:

  1. No runtime permissions needed.
  2. Can easily limit the number of medias picked (min. 1).
  3. Can easily limit the types of medias picked (images, videos, or both).
  4. Uses built-in & standardized UI which is good for user experience.

In this article, we will try to implement this new Photo Picker. Here’s what it will look like at the end:

New Android 13’s Photo Picker in action. You can pick single/multiple photos and/or videos.

Where’s the Source Code?

Step by Step Explanation

Follow the steps provided below to make this application.

1. As of the writing of this article, Android 13 can only be used with the preview release of Android Studio. Therefore, you must go to this page, and download the Canary Build of Android Studio.

2. Once installed, you need to install the Android 13 SDK. You can do this by clicking Tools > SDK Manager. In the SDK Platforms tab, select Android 13. In the SDK Tools tab, select Android SDK Build-Tools 33. Click OK to install the SDK.

3. Once SDK is installed, open the Android Studio. Create new project with Empty Activity option.

4. First off, you need to change the target and compile SDK version of this app. Open app/build.gradle and you would see something like this:

Change the compileSdk and targetSdk to use the Android 13 SDK like shown in the code snippet below. Don’t forget to click Sync Now after.

5. First, we will build the layout of the application. We will be editing the activity_main.xml file. The image below shows how it will look in the end. The layout consists of 4 buttons that activate Photo Picker with different parameters. We also display the maximum number of picked medias at the bottom of the buttons (using getPickImagesMaxLimit API).

What activity_main.xml should look like.

Here’s the content of activity_main.xml:

6. Lastly, we will update the MainActivity.kt file. You can copy-paste the code snippet below. The most important thing to notice is the usage of MediaStore.ACTION_PICK_IMAGES for showing the Photo Picker. Notice also that you can specify the type of medias picked by specifying the Intent’s MIME type and specify the maximum limit of medias picked by using MediaStore.EXTRA_PICK_IMAGES_MAX.

7. That’s it! Now you can run your app and see Photo Picker in action:

The end result of our application.

As always, thanks for reading!

Want to learn more about Android 13?

Check out all of our articles from “Exploring Android 13” series here:

Exploring Android 13 (Tiramisu)

10 stories

--

--