Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select the front camera [duplicate]

I'm using the following code to take a picture:

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            //...
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

Is there any way to select the front camera?


1 Answers

You can try this.

takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);

But not all camera apps supports that flag

like image 192
Andrew Avatar answered Aug 03 '26 23:08

Andrew