Intent 不设置相机参数 [英] Intent does not set the camera parameters
问题描述
我正在从我的应用程序中打开相机应用程序作为外部意图.我正在使用以下代码来调用相机,以下是我的条件:
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:
- 它应该会打开前置摄像头.
- 最高画质.
- 闪光灯必须打开
以下是我的代码:
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" />
我有什么遗漏的吗?
推荐答案
很遗憾,在使用带 Intent 的相机时,唯一可以设置的额外参数是
Unfortunately, when using the camera with Intent, the only extra parameter you can set is
MediaStore.EXTRA_OUTPUT
例如
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 有时可以发挥作用:
Camera Facing intent extra can sometimes work:
action.putExtra("android.intent.extras.CAMERA_FACING", 1);
查看 android 源文件,在 Util 类文件中有一些测试"方法,但没有正式记录:
Looking in the android source files, there are some "test" methods that are in the Util class file but not officially documented:
(实用程序)
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;
}
而在photomodule中,使用了如下方法:
And in the photomodule, the following method is used:
(照片模块)
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);
这篇关于Intent 不设置相机参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!