在Android中打开正面摄像头 [英] Open frontal face camera in android

查看:83
本文介绍了在Android中打开正面摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在设备上打开前置摄像头,但是我尝试的任何方法都无效,并且后置摄像头始终处于打开状态。我正在使用LG G4设备。

I'm trying to open a frontal camera on my device but nothing that I try works and the back camera is always opening. I'm using the LG G4 device.

    File file;
    try {
        File dir = new File(Environment.getExternalStorageDirectory());
        file = File.createTempFile("temp.png", dir);
    } catch (IOException e) {
        AndroidExceptionHandler.handle(e);
    }
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);

    startActivityForResult(cameraIntent, REGISTRO_PONTO_IMAGE_CAM);

我在做什么错了?

推荐答案

您假设所有设备上的所有相机应用都会尊重未记录的,不受支持的 Intent 额外内容。

You are assuming that an undocumented, unsupported Intent extra will be honored by all camera apps on all devices.

大约有20亿个Android设备,由数千种设备型号组成。这些设备型号将附带数百种不同的相机应用程序。用户也可以自己安装相机应用程序。数百个相机应用中的任何一个都可以处理您的 ACTION_IMAGE_CAPTURE 请求。而且,它们都不需额外支付 android.intent.extras.CAMERA_FACING

There are ~2 billion Android devices, made up of thousands of device models. Those device models will ship with hundreds of different camera apps. Users can also install camera apps themselves. Any of those hundreds of camera apps may be what handles your ACTION_IMAGE_CAPTURE request. And none of them have to honor an android.intent.extras.CAMERA_FACING extra.

欢迎您提出 Intent 上的额外费用,并且可能有相机应用程序会对此加以注意。您不应该假设任何相机都会关注它,而用户将决定使用哪种相机拍摄照片。

You are welcome to put that extra on the Intent, and it is possible that there are camera apps that will pay attention to it. You should not assume that any camera will pay attention to it, and it will be up to the user to choose what camera to use for taking the picture.

这篇关于在Android中打开正面摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆