Ändern von KeepScreenOn von Javascript in Android Cordova App

Ich versuche, das Bildschirm-Timeout über meine Cordova-App zu steuern. Die App spielt Videos ab und während die App ein Video abspielt, möchte ich das Zeitlimit für den Bildschirm deaktivieren. Während ein Video angehalten ist oder etwas anderes gemacht wird, möchte ich es wieder einschalten. Wenn ich das KeepScreenOn-Flag in OnCreate setze, funktioniert es einwandfrei, aber wenn ich es von meinem Plugin aus aufrufe, ändert sich nichts. Ich habe beides ausprobiert

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

und

this.webView.setKeepScreenOn(true); 

Hier ist mein Plugin-Code.

package com.Kidobi.plugins;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

import android.view.WindowManager;

public class KeepScreenOn extends CordovaPlugin {

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
    System.out.println("Im in the plugin");
    if (action.equals("KeepScreenOn")) {
        System.out.println("KeepScreenOn");
        this.webView.setKeepScreenOn(true);
        //cordova.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        //callbackContext.success(action);
        return true;
    } else if (action.equals("CancelKeepScreenOn")){
        System.out.println("CancelKeepScreenOn");
        this.webView.setKeepScreenOn(false);
           //cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        //callbackContext.success(action);
        return true;
    } else {
        System.out.println("UNKNOWN");
        callbackContext.error("unknown action" + action);
        return false;
    }
}

}

Antworten auf die Frage(1)

Ihre Antwort auf die Frage