Android bindings example

BindingsDemo example application shows how you can:

  • Use the Kanzi Connect Android bindings (.AAR file) to access Kanzi Connect server and service functionality from a non-Kanzi Android application. The example is created using Android Studio.

  • Bind Kanzi Connect service data elements to Android UI elements in a similar way you can bind service data elements to Kanzi UI elements.

  • Use the Media Service client-side API to control music playback.

  • Use the table-based content provider to query song content from the Kanzi Connect Server.

You can find this example in the <KanziConnectInstallation>/SDK/bindings/android/BindingsDemo directory.

To learn more about the Android data bindings, see Data Binding Library.

Structure of the example

The BindingsDemo Android Studio project contains:

  • MainActivity.java file shows how to create a Kanzi Connect application and register relevant data listeners.

  • activity_main.xml file contains the layout definition that shows how the Kanzi Connect data elements are bound to layout controls.

  • RandomTrackPicker.java simple table based content client that queries URI content://com.rightware.content/playlists for playlists and picks a random track from a random playlist.

  • UrlImageView.java extends Android ImageView and downloads album art image from the Kanzi Connect Server.

  • Namespace com.rightware.connect contains these generated Java files:

    • ClusterRuntimeDataListener.java is the listener for the Cluster service runtime data.

    • SystemRuntimeDataListener.java is the listener for the System service runtime data.

    • MediaRuntimeDataListener.java is the listener for the Media service runtime data.

    • MediaClient.java client-side interface for the Media service controls the music playback.

Running the example

When you run the example the first time, the application asks for access to the device SD card because it tries to read the connection.xml file on the device SD card.

../_images/allow-bindingsdemo-sd-card.png

Once allowed to read, the application connects to the configured Kanzi Connect Server and shows:

  • From the basic Cluster service the speed and power information

  • From the System service the time and date information

  • Media controls and playback status in the bottom part of the screen.

../_images/bindingsdemo-running.png

You can start the music playback by pressing the Play button. The application starts playing a random playlist and a random track in that playlist. Once playing, the application downloads the album art and starts to show the progress of playback similarly to IVI example.

../_images/bindingsdemo-music-playing.png

Since the BindingsDemo application has very limited controls for music playback, it is more convenient to select a playlist and track using the IVI example application. See In-vehicle infotainment example.