5

This is likely an advanced question since I have a a fair bit of experience with developing camera apps for Android and have the basics right. On some phones, when calling

Camera.open(0);

I get a RuntimeException. My camera app works on most phones (1000+ device types of Android) but fails on a few (about 50+ device types). It also appears to be inconsistent across devices meaning the app will always work or fail on the same model of the device. E.g. the app works on some Galaxy S2's but fails on other S2's.

I have couple of logcats:


On Android 4.0.4

05-26 12:22:26.150 I/CameraService( 85): Opening camera 0<br/>
05-26 12:22:26.150 I/NvOmxCamera( 85): HAL_camera_device_open: open camera 0<br/>
05-26 12:22:26.150 D/NvOmxCamera( 85): HAL_openCameraHardware() use_camera_1st_source=1<br/>
05-26 12:22:26.150 E/NvOmxCamera( 85): Invalid camera ID 0, hardware does not support simultaneous CSI camera use<br/>
05-26 12:22:26.150 E/CameraService( 85): Could not open camera 0: -38<br/>
05-26 12:22:26.150 I/CameraService( 85): Destroying camera 0<br/>
05-26 12:22:26.160 D/AndroidRuntime(25895): Shutting down VM<br/>
05-26 12:22:26.160 W/dalvikvm(25895): threadid=1: thread exiting with uncaught exception (group=0x40a5a1f8)<br/>
05-26 12:22:26.180 E/Crittercism(25895): java.lang.RuntimeException: Fail to connect to camera service<br/>
05-26 12:22:26.180 E/Crittercism(25895): at android.hardware.Camera.native_setup(Native Method)<br/>
05-26 12:22:26.180 E/Crittercism(25895): at android.hardware.Camera.<init>(Camera.java:304)<br/>
05-26 12:22:26.180 E/Crittercism(25895): at android.hardware.Camera.open(Camera.java:264)<br/>

On Android 2.3.6

05-26 11:27:16.984 W/CameraSwitch( 7088): open main camera<br/>
05-26 11:27:16.984 W/CameraSwitch( 7088): no file - can't switch camera<br/>
05-26 11:27:16.994 D/CameraService( 66): CameraService::connect E (pid 7088, client 0xad08)<br/>
05-26 11:27:16.994 D/CameraService( 66): CameraService::connect X (pid 7088, new client 0xad08) rejected. (old pid 7173, old client 0x3ca30)<br/>
05-26 11:27:16.994 D/CameraService( 66): The old client is dead!<br/>
05-26 11:27:16.994 D/AndroidRuntime( 7088): Shutting down VM<br/>
05-26 11:27:16.994 W/dalvikvm( 7088): threadid=1: thread exiting with uncaught exception (group=0x400259f8)<br/>
05-26 11:27:17.094 D/dalvikvm( 7088): GC_FOR_MALLOC freed 15803 objects / 957392 bytes in 93ms<br/>
05-26 11:27:17.114 E/Crittercism( 7088): java.lang.RuntimeException: Fail to connect to camera service<br/>
05-26 11:27:17.114 E/Crittercism( 7088): at android.hardware.Camera.native_setup(Native Method)<br/>
05-26 11:27:17.114 E/Crittercism( 7088): at android.hardware.Camera.<init>(Camera.java:118)<br/>
05-26 11:27:17.114 E/Crittercism( 7088): at android.hardware.Camera.open(Camera.java:91)
<br/>

I have tried a lot of things but I just cannot figure out what the problem is. This line of code is one of the first lines to execute (Camera.open()) so it is unlikely the error is in my code. Any insight as to why this line fails on some cameras will be very helpful.

If it is relevant, I am opening the camera from a service. I can post any information that is needed to diagnose this problem. Thanks.

user2421790
  • 81
  • 1
  • 6

1 Answers1

1

do you include camera permissions and features in your app?
if yes, maybe the camera is in use in another app.

from android developers:
"Throws RuntimeException if opening the camera fails (for example, if the camera is in use by another process or device policy manager has disabled the camera)."

  • No, this is not an issue with permissions. Like I said my app works on 1000+ types of Android devices. I do have a question, how could the Camera app be in use by another app. Strictly speaking there could be a background service that has locked the camera but it is unlikely that so many users would have an the camera is use by a background service that they are unaware of. – user2421790 May 26 '13 at 16:36