Search code examples
androidcameratorchflashlight

Android API Level 16 and higher Torch App


I found this Question but it doesn't work for me. (Nothing happens. Tested on Wiko Rainbow Jam) Android - Camera2 : The easiest way to turn on the torch light

My App have to run on min. API Level 16! Is there an SupportCameraManager or an Library (under Apache), which can I use?


Solution

  • SOLUTION: The problem was that I only got the camera's parameters when turning on the light and turning off the light. This must apparently also be done in the constructor or in the overwriting onStart method.

    @Override
    protected void onStart() {
        super.onStart();
    
        camera = Camera.open(); //Also Call this
        params = camera.getParameters(); //and this, in the Constructor
    }
    

    as fields:

    private Camera camera;
    Parameters params;
    

    And then you can start the flashlight with these snippets of code: Android - Camera2 : The easiest way to turn on the torch light