当查询ACTION_IMAGE_CAPTURE的意图时,Android 11(R)返回空列表 [英] Android 11 (R) return empty list when querying intent for ACTION_IMAGE_CAPTURE
问题描述
设备:模拟器像素3a-Android 11
Device: Emulator pixel 3a - Android 11
代码:
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final List<ResolveInfo> listCam =
context.getPackageManager().queryIntentActivities(captureIntent, 0);
使用时:
targetSdkVersion 30
compileSdkVersion 30
listCam的大小为0
listCam size is 0
以及更改为:
compileSdkVersion 29
listCam的大小为1-应该是这样.
listCam size is 1 - as it should be.
使用以下代码:
val captureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
baseActivity.startActivity(captureIntent)
工作正常,并显示相机应用程序.
Works fine and shows the camera app.
您知道为什么queryIntentActivities不返回相机意图吗?
Any idea why queryIntentActivities is not returning the camera intent?
谢谢!
推荐答案
Android 11更改了应用程序查询和与其他应用程序交互的方式.
Android 11 changes how apps can query and interact with other apps.
从文档:
PackageManager
方法可返回有关其他应用程序的结果,例如queryIntentActivities()
会根据调用进行过滤应用程序的< queries>
声明.
The
PackageManager
methods that return results about other apps, such asqueryIntentActivities()
, are filtered based on the calling app's<queries>
declaration.
因此,您需要在 AndroidManifest.xml
中声明< queries>
:
So you need to declare <queries>
in your AndroidManifest.xml
:
<manifest package="com.example">
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
...
</manifest>
这篇关于当查询ACTION_IMAGE_CAPTURE的意图时,Android 11(R)返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!