简体   繁体   中英

Fail to connect to camera service android.hardware.Camera.open

There are many questions similar to this, but still I am facing this issue.

Camera is working, when my app launch from application. But When I relaunching the app (through Intent Service) I am getting following errors.

java.lang.RuntimeException: Fail to connect to camera service 
at android.hardware.Camera.native_setup(Native Method)
at android.hardware.Camera.<init>(Camera.java:410)
at android.hardware.Camera.open(Camera.java:365)

And I tried with these cases like camera.release(); in onResume. But Still I am getting errors.

In Manifest file I specified the permissions. The Permissions are as follows.

  <uses-feature
            android:name="android.hardware.camera"
            android:required="false" />    
  <uses-feature
            android:name="android.hardware.camera.front"
            android:required="false" />
  <uses-feature
            android:name="android.hardware.camera.autofocus"
            android:required="false" /> 

  <uses-permission android:name="android.permission.CAMERA" />

I have the exact same error, with the same permissions as you in my Manifest file. So far, I have found that if I build my app with

android:targetSdkVersion="23"

I get the aforementioned error in Android Marshmallow devices, while if I build my app with targetSdkVersion less than 23 everything works as expected. I am still troubleshooting it, so in case I get anything more I will post an update.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM