Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I started developping an app and I need to use the camera of my phone, and when I use the method Camera.open(), either with cameraId or not, it returns the error "An error occurred while connecting to camera: 0". My AndroidManifest.xml is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.telecombretagne.holowater">
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.autofocus" />
    <uses-feature android:name="android.hardware.flash" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".camera"
            android:label="@string/title_activity_camera"
            android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>
</manifest>

My phone's Android Version is 6.0.1, and it's a BQ Aquaris M5.

Thanks in advance.

Devices that are running Marshmallow requires permission to be set on runtime, here's my answer from another similar question here :)

From https://developer.android.com/training/permissions/requesting.html
Note: Beginning with Android 6.0 (API level 23), users can revoke permissions from any app at any time, even if the app targets a lower API level. You should test your app to verify that it behaves properly when it's missing a needed permission, regardless of what API level your app targets.

Aside from the permissions set in the manifest, you'll need to request/check for permission on runtime. There are sample codes in there you can use, or...

Quick solution,

go to Settings-> Apps->(Your app name)->Permissions and enable the camera permission. Done, although not recommended for final product

then try your app again. Should be working now :D

I tried today, and my app worked without changing anything... that's quite strange because I restarted my pc and my phone a couple of times and it didn't work, and suddently it does XD I checked the permissions in the app as you said and it allows the camera, at least now. So thank you for the advice ;) – Jorge Peris Jun 19, 2016 at 10:05 Sure no problem :) and if possible mark my post as accepted answer if it helped, since it might help others with similar problem.. All the best in your programming :D – Red Dango Jun 21, 2016 at 3:12

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.