Intent Does Not Set the Camera Parameters

Intent does not set the camera parameters

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

Set Camera Size - Parameters vs Intent?

This code allows me to pick image from gallery. Crop and use my aspect ratio. I did similar code for using camera. After user takes picture, it immediately launches an activity to crop the picture.

  Intent photoPickerIntent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
photoPickerIntent.putExtra("crop", "true");
photoPickerIntent.putExtra("outputX", 150);
photoPickerIntent.putExtra("outputY", 150);
photoPickerIntent.putExtra("aspectX", 1);
photoPickerIntent.putExtra("aspectY", 1);
photoPickerIntent.putExtra("scale", true);
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
photoPickerIntent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMAGE);

Android camera settings missing when launched by an Intent

Is there any way to make the camera settings available when the camera is launched from an intent?

The decision of what the UI will be, for the activity that responds to that Intent, is up to the authors of that app. There are hundreds of pre-installed camera apps and countless more available for download from the Play Store and elsewhere. Any of them could be handling your request.

There is nothing documented in the protocol for ACTION_IMAGE_CAPTURE that allows you to request changes to the camera UI, and there is no law on the books anywhere that would force the camera app developers to honor it even if there were.

Camera intent with resolution parameters in Android

Camera intent starts external camera applciation which MAY use your hints (but MIGHT NOT). The activity/application is non standard (phone vendor dependent), as well as the concrete implementation of the camera software.

You can also use the camera api ( working examples are in this project: http://sourceforge.net/projects/javaocr/ ) which allows you to:

  • query supported image formats and resolutions (you guessed it - vendor dependent)
  • set up preview and capure resolutions and formats (but camera software is free to ignore this setting, and some formats and resolutions can produce weird exceptions despite being advertised as supported)

Conclusion: cameras in android devices are different and the camera API is underdocumented mess. So be as defensive as possible.



Related Topics



Leave a reply



Submit