Frage

I tried a code below but it just prevents screen to be slept.

   Window window = getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    window.setAttributes(params);
    window.addFlags(
         WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

What should I use to prevent flashlight stop working during lock. I search though and got above idea. any help would be appreciated. Thanks.

War es hilfreich?

Lösung

Look at this answer, I think you will find it most useful.

You might want to look at this one too.

Cheers

Andere Tipps

Using this code block did the trick for me. This has code from onStop and onPause methods in it so you could remove the code from there and just keep this.

     @Override
    public void onBackPressed() {      
    super.onBackPressed();

    myParameters = myCamera.getParameters();
    myParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
    myCamera.setParameters(myParameters);
    myCamera.stopPreview();
    FlashOn = false;

    if (myCamera != null) {
        myCamera.release();
        myCamera = null;
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top