I'm using an intent to open the camera with the native application:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri photoUri = Uri.fromFile(getOutputPhotoFile()); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); startActivityForResult(intent, CAMERA_PHOTO_REQUEST_CODE);
Every time the camera that is opened (front/back camera) is like the last time this native camera application was open. Meaning that if the last time I closed the native camera application the back camera was active, so when I launch the intent for camera, the back camera will be active.
I want to launch directly the front camera with the intent. Does anybody know how to do that?
Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use onActivityResult() method to get the result, here the captured image.
The Android Camera application encodes the photo in the return Intent delivered to onActivityResult() as a small Bitmap in the extras, under the key "data" . The following code retrieves this image and displays it in an ImageView .
Intent. By the help of 2 constants of MediaStore class, we can capture picture and video without using the instance of Camera class. ACTION_IMAGE_CAPTURE.
Word of caution: its a hack
Add this to the intent
intent.putExtra("android.intent.extras.CAMERA_FACING", 1);
This solution isn't sustainable, its using a testing code of the Camera app. For more info look at the "getCameraFacingIntentExtras" static method in Util class of the AOSP Camera project.
Update: Looks like that it was disabled in L
Taken from Google Camera's shortcut for Android 7.1 (but should work with older Androids)
intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
So, combined with previous answers, this works for me on all phones I could've test it on
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With