2
votes

I'm currently trying to get codename one working with some native code on windows phone. I created a "native demo" project where I changed the NativeCalls class to just support one simple method:

package com.codename1.nativedemo;
import com.codename1.system.NativeInterface;
public interface NativeCalls extends NativeInterface {
    public String testString();
}

from this one i used the context menu item "Generate Native" and changed the NativeCallsImpl.cs file to return "windows phone" when testString is called. The last change I made is within the 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);
    }
}

the build works perfectly fine and it also runs on the simulator. But when I'm deploying the xap file on my phone (via WP Dev Tools, QR code doesn't work, shows "company app couldn't been installed), the app boots normally but shows that the NativeLookup returned null. The built .jar file from within the dist-directory contains the .cs file in the correct location (com/codename1/nativedemo/NativeCallsImpl.cs, right besides NativeCalls.class)

1
In the NativeCallsImpl.cs, did you set the isSupported() method to return true? By default, I think it will be false. I guess this probably won't help the null issue, but it will be the next problem. - James H
yep, it returns true - Gernot Raudner

1 Answers

2
votes

A null is returned by this lookup is an exception is thrown or something failed during creation.

I'm not 100% sure this works properly in the current Windows Phone port.

FYI The current Windows Phone port is deprecated and undergoing a complete rewrite.