How to launch front camera with intent?

Yaniv picture Yaniv · Mar 13, 2012 · Viewed 34.8k times · Source

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?

Answer

user213493 picture user213493 · Jun 22, 2012

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