我想使用 JSNI 在 GWT 上运行此phonegap native 警报
navigator.notification.alert(
'You are the winner!', // message
null, // callback
'Game Over',
'Done'
);
我已经尝试过这个:
public static native void testNativeAlert()/*-{
navigator.notification.alert(
'You are the winner!', // message
null, // callback
'Game Over',
'Done');}-*/;
最佳答案
来自http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#writing ,不要忘记 $wnd
来访问全局属性!
public static native void alert(String msg) /*-{ $wnd.alert(msg); }-*/;
Note that the code did not reference the JavaScript window object directly inside the method. When accessing the browser’s window and document objects from JSNI, you must reference them as $wnd and $doc, respectively. Your compiled script runs in a nested frame, and $wnd and $doc are automatically initialized to correctly refer to the host page’s window and document.
因此,在您的情况下,您必须使用 $wnd
访问 navigator
:
public static native void testNativeAlert()/*-{
$wnd.navigator.notification.alert(
'You are the winner!', // message
null, // callback
'Game Over',
'Done');
}-*/;
<小时/>
旁注:文档不清楚,但您确定phonegap让callback
为空吗?否则请进一步查看我上面链接的 JSNI 文档。
关于java - 使用 JSNI 在 GWT 中使用原生 Phonegape js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29032058/