The following ADB command is not working on Android 11 devices
adb -d shell "am start -a android.media.action.IMAGE_CAPTURE" -W
Results in
Starting: Intent { act=android.media.action.IMAGE_CAPTURE }
Error: Activity not started, unknown error code 102
It seems to be related to the changes in Android 11, see Android 11 (R) return empty list when querying intent for ACTION_IMAGE_CAPTURE and the solution mentioned here is to add this to manifest
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
Is there any equivalent for this in ADB?
This appears to be a bug in Android. The camera activity launch doesn't fail due to the issue you linked to but because of denial from the AppOpsManager
service:
05-04 14:16:51.789 620 2669 W ActivityTaskManager: Appop Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x10000000 cmp=com.android.camera2/com.android.camera.CaptureActivity } from null (pid=4079, uid=2000) requires android:camera
This can be verified via
adb shell appops get com.android.shell
where com.android.shell
is the package name supplied by the command-line utilities such as am
i.e. the Android Shell package. This yields
Uid mode: COARSE_LOCATION: foreground
LEGACY_STORAGE: ignore
CAMERA: allow; rejectTime=+4m37s345ms ago
which shows how long back the rejection for the CAMERA
op was incurred by Shell package.
But this policy of rejection is incorrect since com.android.shell
already has the CAMERA
permission which can be verified via
adb shell dumpsys package com.android.shell|grep 'android.permission.CAMERA'
android.permission.CAMERA
android.permission.CAMERA: granted=true, flags=[ SYSTEM_FIXED|GRANTED_BY_DEFAULT]
One alternative (that might not work for all) is to start this intent from a root shell (after adb root
/su
) which works.
05-04 14:17:23.610 502 2518 I CameraService: CameraService::connect call (PID -1 "com.android.camera2", camera ID 0) for HAL version default and Camera API version 2