I am trying to control the screen timeout from my cordova app. The app plays videos and while the app is playing a video I want to turn off the screen timeout. While a video is paused or they are doing something else I want to turn it back on. If I set the KeepScreenOn flag in OnCreate it works fine however if I call it from my plugin nothing changes. I have tried both
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
and
this.webView.setKeepScreenOn(true);
Here is my 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;
}
}
}