How to turn on front flash light programmatically in Android?

后端 未结 11 1615
执笔经年
执笔经年 2020-11-22 00:17

I want to turn on front flash light (not with camera preview) programmatically in Android. I googled for it but the help i found referred me to this page

Does anyo

11条回答
  •  旧时难觅i
    2020-11-22 00:59

    I Got AutoFlash light with below simple Three Steps.

    • I just added Camera and Flash Permission in Manifest.xml file
    
    
    
    
    
    
    • In your Camera Code do this way.

      //Open Camera
      Camera  mCamera = Camera.open(); 
      
      //Get Camera Params for customisation
      Camera.Parameters parameters = mCamera.getParameters();
      
      //Check Whether device supports AutoFlash, If you YES then set AutoFlash
      List flashModes = parameters.getSupportedFlashModes();
      if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_AUTO))
      {
           parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
      }
      mCamera.setParameters(parameters);
      mCamera.startPreview();
      
    • Build + Run —> Now Go to Dim light area and Snap photo, you should get auto flash light if device supports.

提交回复
热议问题