【问题标题】:How to use intent start front camera? [duplicate]如何使用intent启动前置摄像头? [复制]
【发布时间】:2018-01-08 08:51:34
【问题描述】:

我尝试了其他问题的方法,但对我来说,这些方法不起作用。

我想使用 Intent 启动前置摄像头。 我试着去做

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
mFile = Utils.getVisitorImage();
Uri imageUri = FileProvider.getUriForFile(
                getActivity(),
                getActivity().getPackageName() + ".fileprovider",
                mFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAMERA_PHOTO_REQUEST_CODE);

但是,它不起作用。 我的设备是 Android 7.1.1。 如何使用意图启动前置摄像头? 我希望有人帮助我。谢谢。

【问题讨论】:

  • @kaihello 你添加权限了吗?
  • 我尝试了其他方法,但对我来说,这些方法不起作用
  • @kaihello 没找到你?
  • 我添加了权限,但仍然没有打开前置摄像头。总是后置摄像头。
  • 是相机问题,我换个手机就可以了。

标签: android camera


【解决方案1】:

AndroidManifest.xml文件中添加以下权限:

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />

要调用前置摄像头,您可以使用:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    
intent.putExtra("android.intent.extras.CAMERA_FACING", 1);

【讨论】:

  • 我添加了权限,但还是没有打开前置摄像头。
  • 你能在这里打印你的 LogCat 错误吗?
  • 我给了相机权限,所以没有错误信息
  • 当然它会给出一些关于你的问题的消息@kaihello
猜你喜欢
  • 2017-01-18
  • 2016-01-19
  • 1970-01-01
  • 2016-03-06
  • 2012-03-29
  • 2019-07-19
  • 2013-05-13
  • 1970-01-01
相关资源
最近更新 更多