I'm using the Android APIDemo sample code.
When I run the CameraPreview example, at first it was giving me an error.
I traced that one down and the sample was working for a while.
Now, it no longer works. It says
ERROR/AndroidRuntime(2949): java.lang.RuntimeException: Fail to connect to camera service
What can be causing that? It happens when camera.open()
is called.
Thanks,
Tee
If the camera or flashlight is not working on Android, you can try to clear the app's data. This action automatically Resets the camera app system. Go to SETTINGS > APPS & NOTIFICATIONS (select, “See all Apps”) > scroll to CAMERA > STORAGE > Tap, “Clear Data”. Next, check to see if the camera is working fine.
Step 1: Long-tap on the Camera app icon and open the app info menu. Step 2: Go to Storage & cache menu. Step 3: Tap on Clear cache and you are all set to use a working Camera app on Android.
Be sure to properly release all the aquired camera resources:
@Override public void surfaceDestroyed(SurfaceHolder holder) { if (mCam != null) { mCam.stopPreview(); mCam.setPreviewCallback(null); mCam.release(); mCam = null; } } @Override public void surfaceCreated(SurfaceHolder holder) { if (mCam == null) { mCam = Camera.open(); try { mCam.setPreviewDisplay(holder); // TODO test how much setPreviewCallbackWithBuffer is faster mCam.setPreviewCallback(this); } catch (IOException e) { mCam.release(); mCam = null; } } }
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