This question already has answers here:
How do I open the “front camera” on the Android platform?
                                
                                    (9个答案)
                                
                        
                                2年前关闭。
            
                    
我正在开发一个演示,其中我必须检查设备是否具有前置摄像头,如果设备具有前置摄像头,则必须将其打开以捕获图像。

我搜索了很多,但没有找到任何解决方案。请给我一个解决方案。

提前致谢。

最佳答案

我使用前置摄像头的解决方案:

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;
}


使用相机的完整教程-> HERE

而我的图片结果:

10-05 23:58