问题描述
我尝试在我的phonegap应用中设置 FLAG_SHOW_WHEN_LOCKED
,但仅在显示某个网页时。为此,我在 execute
方法中使用 CordovaPlugin
中的以下代码扩展了一个Java插件:
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;
}
使用 cordova.exec null,'MyPluginClass','showWhenLocked',[myVar])
,但在执行时我得到错误
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.
推荐答案
我已经发现这种错误可以是由需要不可用线程的调用引起。你使用 getWindow()
告诉我,这是更可能的。你很可能访问由另一个线程锁定的信息,如UI线程。查看cordova 在UI线程中的线程部分。
I have found already that this kind of error can be caused by calls that require threads that are not available. Your use of getWindow()
tell me that this is even more likely. You are most likely accessing information locked by another thread, like the UI thread. Check out the cordova documentation in the section about threading in the UI thread.
这篇关于Android& PhoneGap - 调用NPObject上的方法时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!