android java lang runtimeexception fail to connect to camera service

I also saw this error:

java.lang.RuntimeException: Fail to connect to camera service

while experimenting with a flashlight app. Turns out that I was a bit sloppy with my permissions and copied them into the body of the application block in the manifest.xml file. So you REALLY need to obey the syntax as documented in:

http://developer.android.com/guide/topics/manifest/manifest-element.html

Otherwise the app will fail with service connection failure on the Camera.open() call. It should look like this based on your permissions in the question:

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus"/>

<application

Make sure your permission and feature list is contained only in the manifest section, and not buried in the application section!


I had the same issue that none of the answers here solved, so after solving it I am adding my way of solving it. This applies to new android versions that support setting permissions per app (since Marshmallow, 6.0). The permission for camera could be disabled and should be enabled from the app settings. Settings -> Apps -> [Your App] -> Permissions

More info about this here: http://developer.android.com/training/permissions/requesting.html