Kanzi Connect Android bindings

The Kanzi Connect Android bindings shows how to work with generic Kanzi Connect bindings library and generate project-specific extensions.

In the <KanziConnectInstallation>/SDK/bindings/android directory you can find the source files for the example projects:

  • AndroidGradleAarCreator directory contains an Android Studio project that you can use to rebuild generic Kanzi Connect Android bindings library (AAR). For example, use this when you want to customize the helper Java classes. See Using Android bindings.

  • BindingsDemo directory contains an example Android Studio project that shows how you can use the Kanzi Connect Android bindings library (AAR) in a standard Android application. See Android bindings example.

  • AndroidMediaRemoteService directory contains an example Android UI application that runs the Media service and remote content providers for music tracks and simulated playlist which contains all music tracks on the device where the application runs. See Android Media Remote Service.

Integrating the C++ API to Java code

Kanzi Connect uses SWIG (Simplified Wrapper and Interface Generator, www.swig.org) to integrate the Kanzi Connect native C++ API to Java code.

Using of the SWIG is not shown in this topic because the purpose is only to introduce the technology.

This diagram shows the steps required to generate Java bindings to native language modules:

../../_images/swig-diagram.png

SWIG takes the C++ header and instruction files and creates:

  • A Java Native Interface (JNI) compliant C++ file (java_interface.cpp|h) for native interfacing. This file and the original C++ implementation (MyClass.cpp|h) are compiled to a native .so library (native_library.so).

  • A Java file (MyClass.java) that provides a similar API as the C++ class did. You can use the SWIG instructions file to determine how equal this transformation is.

  • A generic bridge between the Java classes and the JNI implementation (projectJNI.java).

Kanzi Connect uses SWIG only to generate Java bindings to generic portions of Kanzi Connect. For project-specific content, such as services and clients, Kanzi Connect generates the Java code which uses this generic portion of Kanzi Connect.