Android打开前置摄像头作为默认 [英] Android open front camera as default

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

问题描述

我需要在我的应用程序中打开前置摄像头作为默认值。如果用户点击按钮,前置摄像头必须打开。

I need to open the front camera as the default in my app. If a user clicks on the button, the front camera must be open.

在我的代码中,我得到当前android设备中存在的摄像头数量,如果

In my code I am getting the number of cameras present in the current android device, and if the device has two cameras, I will take the id of second camera and write some camera logic there.

请帮我建立这个程式码

推荐答案

试试这段代码。它工作正常)。

try this code . It works fine :)

private Camera openFrontFacingCameraGingerbread() {
int cameraCount = 0;
Camera cam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx<cameraCount; camIdx++) {
    Camera.getCameraInfo(camIdx, cameraInfo);
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        try {
            cam = Camera.open(camIdx);
        } catch (RuntimeException e) {
            Log.e("Your_TAG", "Camera failed to open: " + e.getLocalizedMessage());
        }
    }
}
return cam;
}

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

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