2

i am using Camera Api in that when ever i lanch app it will show back camera it works fine but when i click front camera button it will get Runtime excetion Fail to connect camera service

in  camera = Camera.open(cameraID);

in front camera button code :

if (cameraID == Camera.CameraInfo.CAMERA_FACING_BACK)
            {
                Toast.makeText(getApplicationContext(), "Front Camera", Toast.LENGTH_LONG).show();

                cameraID = Camera.CameraInfo.CAMERA_FACING_FRONT;

            }
            else if (cameraID == Camera.CameraInfo.CAMERA_FACING_FRONT)

            {
                Toast.makeText(getApplicationContext(), "Back Camera", Toast.LENGTH_LONG).show();

                cameraID = Camera.CameraInfo.CAMERA_FACING_BACK;

            }

            Intent intent = getIntent();

            finish();

            startActivity(intent);
VR.Naresh
  • 299
  • 7
  • 17

1 Answers1

2

Have you give the permission for front camera:

<uses-permission android:name="android.permission.CAMERA" />
<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" />

Check this link1 & link2 Once.

Community
  • 1
  • 1
Maulik
  • 3,316
  • 20
  • 31
  • still i get error fail to connect camera service please help me still i get error – VR.Naresh Feb 01 '13 at 09:58
  • check my edited answer above I have added one more feature auto focus, try to add in your manifest file – Maulik Feb 01 '13 at 10:03
  • 02-01 15:26:50.199: E/AndroidRuntime(12806): FATAL EXCEPTION: main 02-01 15:26:50.199: E/AndroidRuntime(12806): java.lang.RuntimeException: Fail to connect to camera service – VR.Naresh Feb 01 '13 at 10:04
  • i am using this permissins in manifest uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> – VR.Naresh Feb 01 '13 at 10:14
  • Check this link and check your min sdk version: http://stackoverflow.com/questions/10867830/take-photos-from-front-facing-and-rear-cameras-on-android-2-2 – Maulik Feb 01 '13 at 10:42
  • Try above all links that I have given,I think it will solve your problem. – Maulik Feb 01 '13 at 11:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/23769/discussion-between-the-maulik-and-vr-naresh) – Maulik Feb 01 '13 at 11:04