Native interface: "package android.widget" does not exist???

134 views
Skip to first unread message

kyr...@gmail.com

unread,
Nov 7, 2015, 3:28:57 PM11/7/15
to CodenameOne Discussions
I am trying to implement a native interface into my app. I began with android. I checked out the native demo and Shai's video tutorial and attempted to implement it. However when I try to create a button with android.widget.Button it tells me that "Package android does not exist" This is my code. Is there some sort of package or jar file I need to import in order to do this?? The NativeDemo has the same thing and that seems to work. I don't know what I am doing wrong. Here is my code:

Native Interface:

package info.nightowl.count19;

import com.codename1.system.NativeInterface;
import com.codename1.ui.PeerComponent;
/**
 *
 * @author Kyri
 */
public interface MyNative extends NativeInterface {
    public String returnId();
}

My Native Interface in the android folder:

package info.nightowl.count19;

public class MyNativeImpl {
    public String returnId() {
        android.widget.Button b = new android.widget.Button((android.content.Context)NativeDemo.getContext());
        return null;
    }

    public boolean isSupported() {
        return true;
    }

}

Bare in mind that I do not actually need to create a button. I was just trying out that code because it was in the NativeDemo to see if it would work. The actual class I need is: android.accounts.AccountManager but once again it tells me that package android.accounts does not exist. What am I doing wrong?

Shai Almog

unread,
Nov 7, 2015, 11:29:04 PM11/7/15
to CodenameOne Discussions, kyr...@gmail.com
It won't appear in the completion but it will work when building on the servers for the Android target. E.g. if you are running on a PC we have no way of showing Objective-C completion code and we can't do that for Android since we don't require the Android SDK.

If you are writing a lot of code just write it in Android Studio or some other tool and paste it into Codename One's native interface.

I discussed this here if I recall correctly: https://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html
Reply all
Reply to author
Forward
0 new messages