1

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);

                    }
SHIVA
  • 107
  • 1
  • 11
  • 2
    If you launch a third-party camera app, the user and that app choose what camera to use, not you. If you need control over this, implement the camera code yourself in your own app. – CommonsWare Dec 12 '14 at 20:05
  • I am implementing my own app only, just I am learning how to open front camera on button click, as I am new to Android development – SHIVA Dec 12 '14 at 20:14

2 Answers2

3

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);
0
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
tachyonflux
  • 20,103
  • 7
  • 48
  • 67
  • 2
    This I have tried like Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra("android.intent.extras.CAMERA_FACING", 1); startActivityForResult(intent, IMAGE_CAPTURE); but its not working – SHIVA Dec 12 '14 at 20:40