In my app I use code to take photo from official camera2 sample https://github.com/android/camera-samples/tree/main/Camera2Basic
I updated my app project from 30 SDK to 31 SDK and checked taking photos on Pixel 3 emulator with Android 12 (S) but it fails to take photos with ERROR_CAMERA_DEVICE
error
In official sample it crashes with the same error at https://github.com/android/camera-samples/blob/main/Camera2Basic/app/src/main/java/com/example/android/camera2/basic/fragments/CameraFragment.kt#L286
java.lang.RuntimeException: Camera 0 error: (4) Fatal (device)
at com.example.android.camera2.basic.fragments.CameraFragment$openCamera$2$1.onError(CameraFragment.kt:276)
E/CameraCaptureSession: Session 0: Exception while stopping repeating:
android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
Anyone tried this sample on real device with the newest Android (12)?
CodePudding user response:
Android 12 Emulator issue.
Will be fixed with an update soon https://github.com/android/camera-samples/issues/432#issuecomment-952121904
CodePudding user response:
CameraAccessException
suggests that it has no permission to access the camera device (for whatever reason). Couldn't test on Android 12 yet, as my G100 is still running Android 11.
The code you've linked most definitely doesn't match, because it throws RuntimeException
.
In case the execution reach until there, I'd set a breakpoint and check for the camera
varibale.