-4

I tried other questions' methods, but for me, these methods do not work .

I want to use intent to start front camera. I try to do it

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
mFile = Utils.getVisitorImage();
Uri imageUri = FileProvider.getUriForFile(
                getActivity(),
                getActivity().getPackageName() + ".fileprovider",
                mFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAMERA_PHOTO_REQUEST_CODE);

but,it does't work. my device is Android 7.1.1. How to use intent start front camera? I hope someone help me.Thanks.

kai hello
  • 135
  • 1
  • 2
  • 13

1 Answers1

0

Add the following permissions in the AndroidManifest.xml file:

<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" />

To call the Front camera you can use:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    
intent.putExtra("android.intent.extras.CAMERA_FACING", 1);
Gowtham Subramaniam
  • 3,358
  • 2
  • 19
  • 31