如何在 Android 11 中创建从图库中选择图像的意图?
How to create intent to choose image from gallery in 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”文件中的“查询”块中放入什么才能使此代码正常工作?
将此代码添加到“AndroidManifest”文件中的“queries”块,将使其正常工作。
<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>
希望对您有所帮助。我使用了这个查询参数,它工作正常
我可以像这样在 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”文件中的“查询”块中放入什么才能使此代码正常工作?
将此代码添加到“AndroidManifest”文件中的“queries”块,将使其正常工作。
<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>
希望对您有所帮助。我使用了这个查询参数,它工作正常