Los*_*ost 4 camera android android-intent android-camera android-camera-intent
我打开相机应用程序作为我的应用程序的外部意图.我使用以下代码来调用相机,以下是我的条件:
以下是我的代码:
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);
Run Code Online (Sandbox Code Playgroud)
现在,它确实打开前置摄像头,但它没有打开闪光灯,也没有将图像质量设置为高.
我的清单文件的权限部分如下所示:
<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" />
Run Code Online (Sandbox Code Playgroud)
有什么我想念的吗?
不幸的是,将相机与Intent一起使用时,您可以设置的唯一额外参数是
MediaStore.EXTRA_OUTPUT
Run Code Online (Sandbox Code Playgroud)
例如
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
Run Code Online (Sandbox Code Playgroud)
这允许您映射Camera应用程序将存储图像的位置.
相机面对额外的意图有时可以工作:
action.putExtra("android.intent.extras.CAMERA_FACING", 1);
Run Code Online (Sandbox Code Playgroud)
查看android源文件,有一些"测试"方法在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;
}
Run Code Online (Sandbox Code Playgroud)
在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);
}
}
Run Code Online (Sandbox Code Playgroud)
当相机应用程序初始化照片模式时,它会调用此方法来检查要使用的相机:
mCameraId = getPreferredCameraId(mPreferences);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11088 次 |
| 最近记录: |