Query Audio Picker Intent in Android 11 returns empty

Viewed 858

To check if I have an audio picker on the device so I can show a list of pickers, I query the list of pickers then show intent, it was working on Android 10, but stopped working on Android 11 (resInfoList is empty):

AndroidManifest code :

<queries>
    <intent>
        <action android:name="android.intent.action.PICK" />
        <data android:mimeType="audio/*" />
    </intent>
</queries>

Kotlin Code:

val intent = Intent(Intent.ACTION_PICK, 

MediaStore.Audio.Media.EXTERNAL_CONTENT_URI)
                                    val resInfoList = packageManager.queryIntentActivities(intent, 0)
// this is empty in Android 11, but has items in Android 10`enter code here`
                                    if (resInfoList.isNotEmpty()) {
                                        startActivityForResult(Intent.createChooser(intent, ""), 0)

                                }

The strange point is if I look for video files, it works properly and displays pickers:

AndroidManifest code :

<queries>
    <intent>
        <action android:name="android.intent.action.PICK" />
        <data android:mimeType="video/*" />
    </intent>
</queries>

Kotlin Code:

val intent = Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI)
                                val resInfoList = packageManager.queryIntentActivities(intent, 0)
                                if (resInfoList.isNotEmpty()) {
                                    startActivityForResult(Intent.createChooser(intent, ""), 0)
                                }
0 Answers
Related