android java lang runtimeexception fail to connect to camera service

Jigar Shekh picture Jigar Shekh · May 28, 2014 · Viewed 93.2k times · Source

I am currently working on Flashlight On/OFF. I am getting this error java.lang.RuntimeException: Fail to connect to camera service I don't know why this error is occurring. I referred to many solutions but my problem was still not solved. When flashlight is on, the error does not occur but when the flashlight is off then the error occurs.

My Code Main Code.

My Manifest permission:

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

Answer

sam picture sam · Nov 19, 2015

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