Flash Light not enabling in SAMSUNG Mobile

前端 未结 1 488
野性不改
野性不改 2021-01-07 15:40

I am trying to enable the Flash Light in SamSung mobile but its not getting turned on. here is my code

Camera mycam = Camera.open();
Parameters p = mycam.get         


        
相关标签:
1条回答
  • 2021-01-07 16:25

    This is the workaround I use on my Samsung Galaxy Ace for the flashlight. I essentially continuously auto-focus the camera, because the LED only turns on during auto-focus.

    AutoFocusCallback autoFocusCallback = new AutoFocusCallback();
    autoFocusCallback.setHandler(handler, message);
    //Log.d(TAG, "Requesting auto-focus callback");
    camera.autoFocus(autoFocusCallback);
    
    
    class AutoFocusCallback implements Camera.AutoFocusCallback {
    
      private Handler autoFocusHandler;
      private int autoFocusMessage;
    
      void setHandler(Handler autoFocusHandler, int autoFocusMessage) {
        this.autoFocusHandler = autoFocusHandler;
        this.autoFocusMessage = autoFocusMessage;
      }
    
      public void onAutoFocus(boolean success, Camera camera) {
          Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success)}
          autoFocusHandler.sendMessage(message)
          autoFocusHandler = null;
      }  
    }
    

    TORCH_MODE_ON would be preferable, but since it isn't supported, this is the best way I've found, if you simply must have the flashlight.

    0 讨论(0)
提交回复
热议问题