There was a similar question but it went unresolved:
W/CameraBase﹕ An error occurred while connecting to camera: 0 on camera.open() call
I have an app which (naturally) is using the camera. Its been working fine. However with no code changes, between builds, the app started crashing (verified no code changes via Git commit history).
To further verify the issue is somewhere in the hardware, I ran the same code on another phone and it works just fine. Somehow the camera is locked and won't open.
Here is the relevant code:
Create a previe object
_cameraPreview = new CameraPreview(getActivity(),_camera);
This is the creation code for it
public CameraPreview(Context context, Camera camera)
{
super(context);
_camera = camera;
_surfaceHolder = getHolder();
_surfaceHolder.addCallback(this);
}
Opening the camera:
//Opens back facing camera by default
public static Camera getCameraInstance()
{
Camera c = null;
try
{
c = Camera.open();
}catch (Exception e)
{
e.printStackTrace();
}
return c;
}
This is where the error occurs, camera.Open throws the error with the following stack trace. My camera object is null. This code is from the official Android docs but they don't talk about how to 'release the camera' if its locked from outside the session.
The full log out is
W/CameraBase﹕ An error occurred while connecting to camera: 0
W/System.err﹕ java.lang.RuntimeException: Fail to connect to camera service
W/System.err﹕ at android.hardware.Camera.<init>(Camera.java:497)
W/System.err﹕ at android.hardware.Camera.open(Camera.java:357)
W/System.err﹕ at co.pumpup.app.EditPhotoFragment.getCameraInstance(EditPhotoFragment.java:241)
W/System.err﹕ at co.pumpup.app.EditPhotoFragment.onCreateView(EditPhotoFragment.java:76)
W/System.err﹕ at android.app.Fragment.performCreateView(Fragment.java:2053)
W/System.err﹕ at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
W/System.err﹕ at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
W/System.err﹕ at android.app.BackStackRecord.run(BackStackRecord.java:834)
W/System.err﹕ at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
W/System.err﹕ at android.app.Activity.performStart(Activity.java:6005)
W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:151)
W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5254)
W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Can you advise how I can 'unlock' a locked up camera like this?