Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create intent to choose image from gallery in Android 11?

I can create intent to choose image from gallery on Android in Kotlin like this:

val intentGallery = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
if (intentGallery.resolveActivity(activity.packageManager) != null) {
    // Launch the intent
}

What do I need to put in "queries" block in "AndroidManifest" file on Android 11 (API 30) for this code to work?

Adding this code to "queries" block in "AndroidManifest" file, will make it work just fine.

<package android:name="com.google.android.apps.photos" />

But I want to add a code that covers all image galleries, not just Google's.

Reference: https://developer.android.com/training/basics/intents/package-visibility

like image 334
Harry Avatar asked Nov 02 '20 12:11

Harry


1 Answers

<queries>
    <intent>
        <action android:name="android.intent.action.PICK" />
        <data android:mimeType="vnd.android.cursor.dir/image" />
    </intent>
</queries>

I hope this will help. I used this query parameters and it's works fine

like image 104
Jahongir Bekmuhammetov Avatar answered Nov 12 '22 08:11

Jahongir Bekmuhammetov