Open Source & Free ❤️

Native Interface

Native Interface

Header Image





Picture



Native interfaces allow developers to invoke platform native methods/functions/libraries and even widgets directly from within Codename One without having to adapt your code to every platform. They are a very powerful tool when bridging between Codename One and OS specific features to access functionality that might not yet be exposed in the Codename One platform.



Normally in Java we would use JNI to access “native” however, JNI is designed to access C and we need much more. Codename One allows developers to access Dalvik (Java) when running under Android and defines that as “native”, C# when running in Windows Phone and Objective-C when running under iOS. Because of that it is remarkably hard to map arbitrary objects, callbacks and functionality to a native call. So to simplify that work we placed many restrictions on the construction of a native interface, however you can still accomplish pretty spectacular things such as a

complete working socket implementation

and more.


Check out the new

How Do I? video we just published covering native interfaces

.


































Notice: This post was automatically converted using a script from an older blogging system. Some elements might not have come out as intended…. If that is the case please let us know via the comments section below.

4 Comments

  • Gert says:

    Is EVERYTHING of native code possible in codenameone by native interface?
    In other word, when we assume we built some project by native code, is it possible to build ABSOLUTELY SAME PRODUCT (design, effect and functions etc,,of course, besides execution file size and response speed..) in cd1?
    e.g.
    Like Camera overlaying (for face detection, like MSQRD app, …)

  • Shai Almog says:

    These things can be done in Codename One but “everything” is a bit of a big word.
    Furthermore, lets separate “can” from “should”. If a lot of your code is native and you need a big native interface abstraction this might become painful to the point where Codename One isn’t worth it. I can’t put my finger on an exact point since it varies and this depends on your needs.

  • Gert says:

    Thanks for your kind answer.
    Well, do you have any idea how to build face recognition app in cd1?
    There, the issue for me is just how to get image info in real-time. (during camera showing)
    Best.

  • Shai Almog says:

    Look at how it’s done in native and follow those instructions. I haven’t done this so I can’t really point you at anything.

Leave a Reply