Android Fail to Connect to Camera Service?
<p>I am making an app that needs to use the camera flash.  My code will be below this post, but I get a <code>java.lang.RuntimeException: Fail to connect to camera service</code> when I try to open the camera.  The error comes when the <code>Camera.open();</code> method is called.</p>

<pre><code>Camera camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
camera.startPreview();
</code></pre>

<p>I have tried restarting the phone, closing all apps, and I still get the same error.</p>

<p>Is there a way to release/close the camera before opening it?  I don't know how you would close a null object.</p>

<p>Screen orientation is not a problem as the app is only allowed vertical orientation.</p>

<p>The default camera app works, but not this app.</p>

<p>Error (Full):</p>

<pre><code>    java.lang.RuntimeException: Fail to connect to camera service
        at android.hardware.Camera.native_setup(Native Method)
        at android.hardware.Camera.&lt;init&gt;(Camera.java:319)
        at android.hardware.Camera.open(Camera.java:292)
        at com.bensuniverse.flashlightx.processes.CameraHandler.toggleFlash(CameraHandler.java:21)
        at com.bensuniverse.flashlightx.MainActivity$1.onClick(MainActivity.java:78)
        at android.view.View.performClick(View.java:4106)
        at android.view.View$PerformClick.run(View.java:17052)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5059)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
        at dalvik.system.NativeStart.main(Native Method)
</code></pre>