Failed to connect to camera service
<p>I'm trying to access the camera on my phone. I'm writing a simple stub app prior to putting the code in a widget. I'm not getting very far. The code always throws a runtime exception "failed to connect to camera service" The code(pinched from a commonsware example) which goes wrong is:</p>

<pre><code>    @Override
    public void onResume() {
        super.onResume();
        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.GINGERBREAD) {
            Camera.CameraInfo info = new Camera.CameraInfo();
            for (int i = 0; i &lt; Camera.getNumberOfCameras(); i++) {
                Camera.getCameraInfo(i, info);
                if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                    try {
                        // Gets to here OK
                        camera = Camera.open(i);
                    } catch (Exception e) {
                        e.printStackTrace();
                        //  throws runtime exception :"Failed to connect to camera service"
                    }
                }
            }
        }
}
</code></pre>

<p>and my manifest is <strong>(corrected 20th Oct)</strong>:</p>

<pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nbt.cameratest"
    android:versionCode="1"
    android:versionName="1.0" &gt;
    &lt;uses-sdk android:minSdkVersion="9" /&gt;
    &lt;application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" &gt;
        &lt;activity
            android:label="@string/app_name"
            android:name=".CameraTestActivity" &gt;
            &lt;intent-filter &gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;

            &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
            &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
    &lt;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p>Can anyone please suggest what might be wrong?</p>

<p>UPDATE 20th Oct</p>

<p>Logcat in SDK 4.0 is broken and wont show the end of the log, so I've cut this bit as best as I can from command line adb logcat:</p>

<pre><code>W/ServiceManager( 2588): Permission failure: android.permission.CAMERA from uid=10136 pid=5744
E/CameraService( 2588): Permission Denial: can't use the camera pid=5744, uid=10136
W/System.err( 5744): java.lang.RuntimeException: Fail to connect to camera service
W/System.err( 5744):    at android.hardware.Camera.native_setup(Native Method)
W/System.err( 5744):    at android.hardware.Camera.&lt;init&gt;(Camera.java:294)
W/System.err( 5744):    at android.hardware.Camera.open(Camera.java:255)
etc..
</code></pre>

<p>I don't know why I haven't permission as it is declared in the manifest </p>
