5

I am opening camera app as external intent from my applications. I am using following code to invoke the camera and following are my conditions:

  1. It should open the front camera.
  2. Highest picture quality.
  3. Flash light has to be on

Following is my code:

Intent action = new Intent("android.media.action.IMAGE_CAPTURE");   

        action.putExtra("android.intent.extras.CAMERA_FACING", 1);
        action.putExtra("android.intent.extras.FLASH_MODE_ON", 1);
        action.putExtra("android.intent.extras.QUALITY_HIGH", 1);

Now, it does open the front camera BUT it does not turn on the flash and it does not set the picture quality to high.

My Manifest file's permission section looks like following:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />

is there anything that I am missing?

Lost
  • 12,007
  • 32
  • 121
  • 193

2 Answers2

9

Unfortunately, when using the camera with Intent, the only extra parameter you can set is

MediaStore.EXTRA_OUTPUT

Eg

fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name

Which allows you to map where the Camera application will store the image.

Camera Facing intent extra can sometimes work:

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

Looking in the android source files, there are some "test" methods that are in the Util class file but not officially documented:

(Util)

private static final String EXTRAS_CAMERA_FACING =
        "android.intent.extras.CAMERA_FACING";

// This is for test only. Allow the camera to launch the specific camera.
public static int getCameraFacingIntentExtras(Activity currentActivity) {
    int cameraId = -1;

    int intentCameraId =
            currentActivity.getIntent().getIntExtra(Util.EXTRAS_CAMERA_FACING, -1);

    if (isFrontCameraIntent(intentCameraId)) {
        // Check if the front camera exist
        int frontCameraId = CameraHolder.instance().getFrontCameraId();
        if (frontCameraId != -1) {
            cameraId = frontCameraId;
        }
    } else if (isBackCameraIntent(intentCameraId)) {
        // Check if the back camera exist
        int backCameraId = CameraHolder.instance().getBackCameraId();
        if (backCameraId != -1) {
            cameraId = backCameraId;
        }
    }
    return cameraId;
}

And in the photomodule, the following method is used:

(PhotoModule)

private int getPreferredCameraId(ComboPreferences preferences) {
    int intentCameraId = Util.getCameraFacingIntentExtras(mActivity);
    if (intentCameraId != -1) {
        // Testing purpose. Launch a specific camera through the intent
        // extras.
        return intentCameraId;
    } else {
        return CameraSettings.readPreferredCameraId(preferences);
    }
}

And when the camera app initialises the photo mode, it calls this method to check which camera to use:

mCameraId = getPreferredCameraId(mPreferences);
frogmanx
  • 2,620
  • 1
  • 18
  • 20
  • Which means that I have to do the SurfaceLayOut? There is no way to do flash light and resolution settings from here? – Lost Oct 29 '13 at 23:20
  • If that's the case, how did this work? action.putExtra("android.intent.extras.CAMERA_FACING", 1). It successfully switched between front and back camera. – Lost Oct 29 '13 at 23:21
  • Yeah, I think it depends on if the particular camera app that you are using supports extra intents. http://developer.android.com/guide/topics/media/camera.html#intent-image – frogmanx Oct 29 '13 at 23:32
  • 2
    Yeah, I think it can sometimes depend on api level of the phones and manufacturer's own implementation of camera app – frogmanx Oct 29 '13 at 23:35
  • OK. so at this moment I think the only option I have is to to SurfaceView and instantiate Camera Object and pass in all the parameters into it.. correct? – Lost Oct 29 '13 at 23:36
  • Is there any good tutorial which can help me ipen camera in surface view? I can open up a new question if you would like? – Lost Oct 29 '13 at 23:46
0
intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);

this is an intent to start capture with the front camera instead of the default rear camera.

this works as it is used in this popular cordova plugin in this link at line 145 : https://github.com/EddyVerbruggen/VideoCapturePlus-PhoneGap-Plugin/blob/master/src/android/nl/xservices/plugins/videocaptureplus/VideoCapturePlus.java

hope this helps anyone facing the same problem.

also do you know if you can set an intent to disable the camera controls(filters,switch between cameras..etc) , so that they doesn't show ?

eddy
  • 79
  • 1
  • 7
  • That is a constant, and it is always 1, so that is exactly the same as in the question: `action.putExtra("android.intent.extras.CAMERA_FACING", 1);` – Hugo Jan 25 '17 at 17:04