【发布时间】:2016-01-27 11:29:59
【问题描述】:
我目前正在尝试使用 Windows Phone 上的一些本机代码来使用代号一。我创建了一个“本机演示”项目,在其中更改了 NativeCalls 类以仅支持一种简单的方法:
package com.codename1.nativedemo;
import com.codename1.system.NativeInterface;
public interface NativeCalls extends NativeInterface {
public String testString();
}
从这个我使用上下文菜单项“生成本机”并更改 NativeCallsImpl.cs 文件以在调用 testString 时返回“windows phone”。我所做的最后一个更改是在StateMachine:
protected void onGUI1_AddNativeButtonAction(Component c, ActionEvent event) {
super.onGUI1_AddNativeButtonAction(c, event);
try {
NativeCalls n = (NativeCalls) NativeLookup.create(NativeCalls.class);
if (n != null) {
if (n.isSupported()) {
Dialog.show("Got string", n.testString(), "OK", null);
} else {
Dialog.show("Error", "Platform not supported!", "OK", null);
}
} else {
Dialog.show("Error", "Native lookup returned null!", "OK", null);
}
c.getComponentForm().revalidate();
} catch (Throwable t) {
Dialog.show("Error", "Exception during native access: " + t, "OK", null);
}
}
构建工作得非常好,它也可以在模拟器上运行。但是当我在手机上部署 xap 文件时(通过 WP Dev Tools,二维码不起作用,显示“无法安装公司应用程序),应用程序正常启动,但显示 NativeLookup 返回 null。在 dist 目录中构建的 .jar 文件包含正确位置的 .cs 文件(com/codename1/nativedemo/NativeCallsImpl.cs,就在 NativeCalls.class 旁边)
【问题讨论】:
-
在NativeCallsImpl.cs中,你有没有设置isSupported()方法返回true?默认情况下,我认为这将是错误的。我想这可能对 null 问题没有帮助,但这将是下一个问题。
-
是的,它返回 true
标签: mobile windows-phone-8.1 codenameone