I'm trying to set FLAG_SHOW_WHEN_LOCKED
in my phonegap app, but only when a certain page is shown. To do so, I have a Java plugin extending from CordovaPlugin
with the following code in the execute
method:
if (action.equals("showWhenLocked")) {
boolean showWhenLocked = args.getBoolean(0);
if (showWhenLocked) {
this.cordova.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
} else {
this.cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
callbackContext.success();
return true;
}
It gets called with cordova.exec(null, null, 'MyPluginClass', 'showWhenLocked', [myVar])
, but on execution I get the error
Uncaught Error: Error calling method on NPObject. at file:///android_asset/www/cordova-2.2.0.js:984
Any ideas what's causing this/what I'm doing wrong and how to fix it? If I set the flag upon creating the activity it works just fine.