Android: how to check the flash light is available on device?

前端 未结 4 488
一生所求
一生所求 2021-01-18 10:27

How I check the flash light available on device?also want to know how can I On/Off the flash light? I have put the code but not working right now? I search out this

4条回答
  •  滥情空心
    2021-01-18 10:53

    boolean hasFlash =this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
    

    or

    public boolean hasFlash() {
            if (camera == null) {
                return false;
            }
    
            Camera.Parameters parameters = camera.getParameters();
    
            if (parameters.getFlashMode() == null) {
                return false;
            }
    
            List supportedFlashModes = parameters.getSupportedFlashModes();
            if (supportedFlashModes == null || supportedFlashModes.isEmpty() || supportedFlashModes.size() == 1 && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) {
                return false;
            }
    
            return true;
        }
    

提交回复
热议问题