Why does my app crash when using android.hardware.Camera.Open()?

stringlapse picture stringlapse · Dec 29, 2016 · Viewed 10.1k times · Source

I am re-writing an app for most versions of Android. The app is set to call android.hardware.Camera.Open() on launch. When the app launches it gives the error Camera Error: Could not connect to camera

The permissions in AndroidManifest.xml are

<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.camera"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>`.

Why can't it connect to the camera?

Answer

stringlapse picture stringlapse · Dec 29, 2016

Problem solved!

The issue was simply a matter of capitalization. The line <uses-permission android:name="android.permission.camera"/> should actually read <uses-permission android:name="android.permission.CAMERA"/>. This happened because camera is a hardware feature, while CAMERA is a permission.