Android 6.0 RuntimeException: Fail to connect to camera service

HelloSilence picture HelloSilence · Oct 22, 2015 · Viewed 17.3k times · Source

An error occurred with my app which ran in Nexus5 (Android6.0).

The error was

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

I had added the permission to the AndroidManifest.xml.

But the app is OK with another phone(Android5.1), and genymotion AVD(Android 4.0).

The key code is below

 @Override
public void onResume() {
    super.onResume();
    try {
        mCamera = Camera.open();
    }catch (Exception e){
        Log.e(TAG,"open camera failed",e);
    }

}

Answer

fahad_sust picture fahad_sust · Nov 8, 2015

Write in your gradle.build targetSdkVersion 22. It is a temporary solution but work.