Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fail to connect to camera service

Tags:

java

android

I had my camera set to this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); and it works fine but if I change it to PORTRAIT instead of LANDSCAPE then it crashes with the following error...

07-30 12:51:37.655: ERROR/AndroidRuntime(22069): FATAL EXCEPTION: main
07-30 12:51:37.655: ERROR/AndroidRuntime(22069): java.lang.RuntimeException: Fail to connect to camera service
07-30 12:51:37.655: ERROR/AndroidRuntime(22069):     at android.hardware.Camera.native_setup(Native Method)
07-30 12:51:37.655: ERROR/AndroidRuntime(22069):     at android.hardware.Camera.<init>(Camera.java:110)
07-30 12:51:37.655: ERROR/AndroidRuntime(22069):     at android.hardware.Camera.open(Camera.java:90)
07-30 12:51:37.655: ERROR/AndroidRuntime(22069):     at org.digital.com.CamLayer.surfaceCreated(CamLayer.java:3

The method it crashes in is..

public void surfaceCreated(SurfaceHolder holder) {
    synchronized(this) {
        mCamera = Camera.open();

        Camera.Parameters p = mCamera.getParameters(); 
        p.setPreviewSize(800, 480);
        mCamera.setParameters(p);

        try {
            mCamera.setPreviewDisplay(holder);
        } catch (IOException e) {
            Log.e("Camera", "mCamera.setPreviewDisplay(holder);");
        }

        mCamera.startPreview();
        mCamera.setPreviewCallback(this);
    }
}

It crashes at mCamera = Camera.open();

My Manifest file has <uses-permission android:name="android.permission.CAMERA"></uses-permission>

How do I fix this so I can view my app in Portrait?

like image 614
Skizit Avatar asked Jul 30 '10 13:07

Skizit


2 Answers

Another possibility if you're using an Android Emulator may be that the front and back cameras are defined as "none" in the Android Virtual Device settings.

like image 76
Dave Burke Avatar answered Nov 13 '22 10:11

Dave Burke


Do you have this set in AndroidManifest.xml ?

uses-permission android:name="android.permission.CAMERA"
like image 45
Romain Hippeau Avatar answered Nov 13 '22 10:11

Romain Hippeau