Kotlin “Support” on Zebra Enterprise Devices

With the announcement of Kotlin support in Android studio at Google I/O  2017, Kotlin has been gaining in traction and visibility in the Android developer community.

Since you can easily call Java code from Kotlin and vice-versa it is no surprise that it is possible to develop an application in Kotlin that makes use of Zebra value-adds such as the barcode scanner, utilizing the EMDK for Android (Java) API.

Example

Pre-requisites:

  • EMDK for Android installed that supports API level 23.  At the time of writing this is EMDK 6.6, which is the latest release.  This WILL work with other API support levels, this is just the version configured in the sample gradle file.
  • A Zebra mobile computer connected with USB debugging enabled.
  • Android Studio 3.0

The code

Zebra officially support a Java-based sample showing how to programmatically control the barcode scanner, known as BarcodeSample1: https://github.com/Zebra/samples-emdkforandroid-6_6/tree/BarcodeSample1

For the sake of this demo, I have converted this sample to Kotlin using the Android Studio feature ‘Convert Java file to Kotline file CTRL+ALT+SHIFT+K’.

I have forked the official Zebra repository and created a new branch based on Zebra’s BarcodeSample1, this new branch is called BarcodeSample1-Kotlin shows the demo app running Kotlin: https://github.com/darryncampbell/samples-emdkforandroid-6_6/tree/BarcodeSample1-Kotlin

You can see the differences between the two branches by comparing a pull request or just see the Kotlin file directly.

The APK

There is not a great deal to be gleaned by running the APK since it looks and behaves exactly like the existing Java BarcodeSample1 but I have attached it here anyway: app-release

Conclusion

Obviously this does not show a greenfield Kotlin application and if anything it shows that the ‘Convert Java file to Kotlin’ feature of the IDE works (though I did have to make a few tweaks).  This is just a proof of concept to show that it IS POSSIBLE to create an enterprise application that runs on Zebra mobile computers, making use of their value added hardware.

Although it does work, Kotlin is not officially supported by Zebra at the time of writing though you can have your voice heard by posting about it on Zebra’s developer portal.

Leave a Reply

Your email address will not be published. Required fields are marked *