2

I have a different scenario. I have the camera input connected to the android device. As per the steps given, I have initialized the camera object and the display is working perfectly as excepted.

I have separate code for receiving the camera disconnect information from the underlying linux kernel. In that case, I have to close the camera. Again, if the camera is connected back, I have to make the display resume back.

Scenario 1: When the camera disconnect information is obtained, I tried following functions

Cameraobject.setPreviewCallBack(null);
CameraObject.stopPreview();
CameraObject.release();

Problem: The control loops within these functions.

Scenario 2: I have commented the above lines. Instead, in the code section which gets executed when the camera gets connected again I have called them.

Cameraobject.setPreviewCallBack(null);
CameraObject.stopPreview();
CameraObject.release();
Cameraobject = Camera.open(cameraID);

Problem: Here it gets a runtime error. Could not be connected to camera service.

  • Can you post the runtime error which you get? – Niko Dec 13 '13 at 10:05
  • Have you tried running the callback with Handler and Runnable? Could be some thread timing issue, since you are getting the message from kernel here and the system might need some delay to run the release open code again. – Niko Dec 13 '13 at 10:13
  • 01-01 10:49:10.351: W/System.err(557): java.lang.RuntimeException: Fail to connect to camera service 01-01 10:49:10.351: W/System.err(557): at android.hardware.Camera.native_setup(Native Method) 01-01 10:49:10.351: W/System.err(557): at android.hardware.Camera.(Camera.java:345) 01-01 10:49:10.351: W/System.err(557): at android.hardware.Camera.open(Camera.java:303) – user3098790 Dec 13 '13 at 10:21
  • Here are some good posts about camera usage: http://stackoverflow.com/questions/3371692/fail-to-connect-to-camera-service – Niko Dec 13 '13 at 10:25

2 Answers2

1

Are you added appropriate permissions defined in your manifest.?

android.permission.CAMERA
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
  • Permissions should not be a problem: "I have initialized the camera object and the display is working perfectly as excepted." – Niko Dec 13 '13 at 10:06
0

add in manifest file

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
The Ray of Hope
  • 738
  • 1
  • 6
  • 16