0

I'm going through this tutorial for Cameras and Android.

But I constantly get the error: java.lang.RuntimeException: Fail to connect to camera service

Here is my Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstapp">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity android:name=".DisplayMessageActivity" />


        <activity android:name=".CameraActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape">
        </activity>



</application>
</manifest>

I think the reason is that the class android.hardware.Camera is deprecated. Is that possible?

If the reason for this error is that the class android.hardware.Camera is deprecated, then I need to use the class android.hardware.Camera2;?

K.Os
  • 5,123
  • 8
  • 40
  • 95
Jenia Ivanov
  • 2,485
  • 3
  • 41
  • 69
  • So many hits for that exception message. https://stackoverflow.com/q/26305107/1531971 https://stackoverflow.com/q/10100351/1531971 https://stackoverflow.com/q/7829162/1531971 –  Oct 02 '17 at 20:13
  • Possible duplicate of [android java lang runtimeexception fail to connect to camera service](https://stackoverflow.com/questions/23904459/android-java-lang-runtimeexception-fail-to-connect-to-camera-service) – Dima Kozhevin Oct 02 '17 at 20:14

2 Answers2

0

You can use android.hardware.Camera even if it is deprecated, I think you didn't ask user for camera permission programatically, you should check android developers pages for permission changes from android 6.0...

zvone
  • 39
  • 2
0

if you are trying in Marshmallow then follow following

1: Request the permissions you need

2: Handle the permissions request response

For more: https://developer.android.com/training/permissions/requesting.html