Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Fail to connect to camera

Tags:

android

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

like image 910
teepusink Avatar asked Apr 01 '10 22:04

teepusink


People also ask

Why is my camera not connecting to my phone?

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.

Why is my Camera app not working Android?

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.


1 Answers

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;         }     } } 
like image 136
Kangur Avatar answered Sep 28 '22 15:09

Kangur