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" />

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值