我打开摄像头的应用程序从我的应用程序的外部意图。我使用下面的code调用摄像头和下面是我的情况:
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:
应该打开前置摄像头。 在最高图像质量。 在闪光灯发出的光线要上以下是我的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?
推荐答案
不幸的是,使用意图相机时,唯一额外的参数可以设置为
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 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:
(的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;
}
和在photomodule,下面的方法被用于:
And in the photomodule, the following method is used:
(PhotoModule)
(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);
相关推荐
最新文章