我試圖從我的科爾多瓦應用程序中控制屏幕超時。該應用正在播放視頻,當應用正在播放視頻時,我想關閉屏幕超時。當視頻暫停或他們正在做其他事情時,我想將其重新打開。 如果我在OnCreate中設置了KeepScreenOn標誌,它可以正常工作,但是如果我從插件調用它,則不會發生任何更改。我曾經嘗試都在Android中改變KeepScreenOn javascript cordova app
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;
}
}
}
+1謝謝,這真的幫了我。 :) – unexist