Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to camera service when using ACTION_IMAGE_CAPTURE

Tags:

android

I'm using the following code to tell the system I want to take a picture:

            Intent intent = new Intent(
                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE, null);
            intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri
                    .fromFile(new File(filePath)));
            startActivityForResult(intent, TAKE_PHOTO_ACTIVITY);

It works like a champ, the first time. Subsequent tries yield the following exception:

E/CameraHolder( 8300): java.lang.RuntimeException: Fail to connect to camera service E/CameraHolder( 8300): at android.hardware.Camera.native_setup(Native Method) E/CameraHolder( 8300): at android.hardware.Camera.(Camera.java:110) E/CameraHolder( 8300): at android.hardware.Camera.open(Camera.java:90) E/CameraHolder( 8300): at com.android.camera.CameraHolder.open(CameraHolder.java:100) E/CameraHolder( 8300): at com.android.camera.Camera.ensureCameraDevice(Camera.java:1626) E/CameraHolder( 8300): at com.android.camera.Camera.startPreview(Camera.java:1686) E/CameraHolder( 8300): at com.android.camera.Camera.access$5800(Camera.java:94) E/CameraHolder( 8300): at com.android.camera.Camera$5.run(Camera.java:949) E/CameraHolder( 8300): at java.lang.Thread.run(Thread.java:1096)

I imagine I have to somehow release the camera object, but since I'm not directly acquiring it, I have no idea how to do this. Can someone help me out?

like image 264
synic Avatar asked Mar 02 '11 02:03

synic


1 Answers

You do not need to release the camera object - it is even impossible because you do not have a handle to it. This object is released inside the capture activity you are calling.

Are you always using the same file path? If yes try to generate a unique one each time. If this do not help, it looks evidently like a device specific bug.

like image 152
Urboss Avatar answered Oct 16 '22 01:10

Urboss