android pie so关闭,android - Android Pie:如何使用Camera Intent打开前后摄像头? CAMERA_FACING等于不工作 - 堆栈内存溢出...

我正在尝试在android中打开前后摄像头,这是我打开摄像头的功能:

private void dispatchTakePictureIntent() {

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

// Ensure that there's a camera activity to handle the intent

if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {

// Create the File where the photo should go

File photoFile = null;

try {

photoFile = createImageFile();

} catch (IOException ex) {

// Error occurred while creating the File

}

// Continue only if the File was successfully created

if (photoFile != null) {

Uri photoUri;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

photoUri = FileProvider.getUriForFile(getContext(), getContext().getApplicationContext().getPackageName() + ".provider", photoFile);

} else {

photoUri = Uri.fromFile(photoFile);

}

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);

if (formElement.getElemntType().equalsIgnoreCase("FRONT_CAMERA")) {

takePictureIntent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);

takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);

} else {

takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", Camera.CameraInfo.CAMERA_FACING_BACK);

}

startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);

}

}

}

我有一个来自服务器的表单元素对象。 基于该对象的属性,我需要打开后置摄像头和前置摄像头。 我已在清单文件中添加了摄像头权限,并在清单中的行下方添加了

android:name="android.hardware.camera"

android:required="false" />

android:name="android.hardware.camera.front"

android:required="false" />

请建议我该如何处理这种情况。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部