How to create intent to choose image from gallery in Android 11?(如何在Android 11中创建从图库中选择图片的意图?)
问题描述
我可以在Kotlin的Android上创建从图库中选择图片的意图,如下所示:
val intentGallery = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
if (intentGallery.resolveActivity(activity.packageManager) != null) {
// Launch the intent
}
要使此代码正常工作,我需要在Android 11(API 30)的&androidManifest";文件中的";queries";块中放入什么内容?
将此代码添加到&qot;androidManifest";文件中的";查询&qot;块中,将使其正常工作。
<package android:name="com.google.android.apps.photos" />
但我想添加一个涵盖所有图片库的代码,而不仅仅是Google的图片库。
参考资料: https://developer.android.com/training/basics/intents/package-visibility推荐答案
<queries>
<intent>
<action android:name="android.intent.action.PICK" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent>
</queries>
我希望这会有所帮助。我使用了这个查询参数,它工作得很好
这篇关于如何在Android 11中创建从图库中选择图片的意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!