Opening flashlight in android with different modes

南笙酒味 提交于 2019-12-04 10:25:29

You can open flashlight in different modes if different flash modes are supported in your device. You can get the code from this open source camera code. OPenCamera

Roman Black

Yes, if You check that device supports torch. But You can encounter a Device-Specific issue that is very prevalent in the Android. You can find more information in this post.

you should check supported flash modes to not have an exception, setFlashMode method checks for supported modes but checking with this method is helpful to set flash mode button or view on UI

public List<String> getSupportedFlashModes() {
    return params.getSupportedFlashModes();
}

Sum of all Flash modes are:

Camera.Parameters.FLASH_MODE_AUTO, Camera.Parameters.FLASH_MODE_OFF, Camera.Parameters.FLASH_MODE_ON, Camera.Parameters.FLASH_MODE_RED_EYE, Camera.Parameters.FLASH_MODE_TORCH

But some or any of these flash modes may not be available in your device, check before using. After selecting from flash modes you can set the flash modes using this method

public synchronized void setFlashMode(String flashMode) {
        Camera.Parameters params = mCamera.getParameters();
        if (cameraId == Camera.CameraInfo.CAMERA_FACING_BACK && params.getSupportedFlashModes() != null
            && params.getSupportedFlashModes().contains(flashMode)) {
        params.setFlashMode(flashMode);
        mCamera.setParameters(params);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!