4

要检查设备上是否有音频选择器以便我可以显示选择器列表,我查询选择器列表然后显示意图,它在 Android 10 上工作,但在 Android 11 上停止工作(resInfoList 为空):

AndroidManifest 代码:

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

科特林代码:

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)

                                }

奇怪的是,如果我查找视频文件,它可以正常工作并显示选择器:

AndroidManifest 代码:

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

科特林代码:

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)
                                }
4

0 回答 0