Using Android 13 Permissionless PhotoPicker in Flutter

Sk Ahron
Level Up Coding
Published in
2 min readNov 20, 2022

--

Android 13 provides a new way of picking files without asking for permission to pick media files.

taken from android developers

In this article, I will show how you can use this photo picker in your flutter apps for APIs above 32.

Let’s begin

Here is the GitHub link

Step 1: create a new flutter project name photo_picker_demo.

Step 2: Now, before working with the photo picker on the android side. we need to create a method channel that will invoke the functionality of opening the new photo picker in android 13.

In MainActivity.kt file you need to register the method channel and pass the handler for that method channel.

make sure to extend MainActivity with FlutterFragmentActivity, not FlutterActivity as it provides functionalities for photo picking

Step 3: Now, we will create a handler for our channel.

Here I am registering for activity results and the contract is PickVisualMedia. You can understand the contract as input that you want to pass.

To this register for activity result. you need to add dependencies.

Set compileSdk to 33

implementation("androidx.activity:activity-ktx:1.6.1")
implementation "androidx.fragment:fragment-ktx:1.5.4"

And now depending on the media type you want to choose, we can use different Request Types.

You can choose multiple files as well by passing the number of items you want to choose.

Step 4: Now, we will create an instance of MethodChannel and call the pickMedia method and passing media type you want to choose.

Output:

Here, I am choosing only image

Thank You for reading

--

--

Hi, I am Shaik Ahron. I am enthusiastic about mobile development. I am open to freelancing, contract roles, and full-time opportunities.