How do I open the “front camera” on the Android platform?

前端 未结 9 2363
挽巷
挽巷 2020-11-22 15:00

More generally, if a device has more than one embedded camera, is there a way to initialize one of them in particular?

I didn\'t find it in Android reference documen

9条回答
  •  甜味超标
    2020-11-22 15:39

    Camera camera;   
    if (Camera.getNumberOfCameras() >= 2) {
    
        //if you want to open front facing camera use this line   
        camera = Camera.open(CameraInfo.CAMERA_FACING_FRONT);
    
        //if you want to use the back facing camera
        camera = Camera.open(CameraInfo.CAMERA_FACING_BACK);                
    }
    
    try {
        camera.setPreviewDisplay("your surface holder here");
        camera.startPreview();      
    } catch (Exception e) {  
        camera.release();
    }
    

    /* This is not the proper way, this is a solution for older devices that run Android 4.0 or older. This can be used for testing purposes, but not recommended for main development. This solution can be considered as a temporary solution only. But this solution has helped many so I don't intend to delete this answer*/

提交回复
热议问题