我正在尝试从我的科尔多瓦应用程序控制屏幕超时。该应用程序播放视频,当应用程序播放视频时,我想关闭屏幕超时。当视频暂停或他们正在做其他事情时,我想重新打开它。如果我在 OnCreate 中设置 KeepScreenOn 标志,它可以正常工作,但是如果我从我的插件中调用它,则没有任何变化。我都试过了
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
和
this.webView.setKeepScreenOn(true);
这是我的插件代码。
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;
}
}
}