How to use camera flash/led as torch on a Samsung Galaxy Tab?

前端 未结 4 917
孤独总比滥情好
孤独总比滥情好 2020-12-02 12:59

I\'m facing to a problem with a Samsung Galaxy Tab. I want to use the camera flash as torch.

Does anyone know how to enable it ?

Hereby a code that works to

4条回答
  •  伪装坚强ぢ
    2020-12-02 13:07

    This is how I turn on and of the torch in LG Nexus 4 and Samsung Galaxy Ace 2.

    public void changeTorch() {
                try {
                    camera = Camera.open();
                    // try to open the camera to turn on the torch
                    Camera.Parameters param = camera.getParameters();
                    param.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
                    camera.setParameters(param);
                    camera.startPreview(); // needed for some devices
                    Log.v("BSW torch", "Torch ON");
                } catch (Exception e) {
                    // if open camera fails, try to release camera
                    Log.w("BSW torch", "Camera is being used trying to turn Torch OFF");
                    try {
                        camera.release();
                    } catch (Exception ex) {
                        Log.e("BSF torch", "Error releasing camera");
                    }
                }
            }
    

提交回复
热议问题