Device: Emulator pixel 3a - Android 11
Code:
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);
When using:
targetSdkVersion 30 compileSdkVersion 30
listCam size is 0
and when changing to:
compileSdkVersion 29
listCam size is 1 - as it should be.
Using the following code:
val captureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) baseActivity.startActivity(captureIntent)
Works fine and shows the camera app.
Any idea why queryIntentActivities is not returning the camera intent?
Thanks!
Android 11 changes how apps can query and interact with other apps.
From the docs:
The
PackageManager
methods that return results about other apps, such asqueryIntentActivities()
, are filtered based on the calling app's<queries>
declaration.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With