How to open Android front camera intent

6.1k views Asked by At

I want to open the front camera in nexus 7 but I am not to open it is always opening back camera then Manually I am selecting the front cam through my android program how can I open always front camera first I have tried This links but not working for me.

@present I am using below code to open camera and take the image

button2.setOnClickListener(new View.OnClickListener() {
                    private static final int IMAGE_CAPTURE = 102;
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    
                        intent.putExtra ("camerasensortype", 2);
                        startActivityForResult(intent, IMAGE_CAPTURE);

                    }
2

There are 2 answers

1
tachyonflux On
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
0
Sachin Sharma On

There you go :) working on 5X (7.0), MI3 (6.0), S3 Neo (4.4)

Intent launchIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
                            launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            launchIntent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
                            launchIntent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
                            launchIntent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
startActivity(launchIntent);