Getting Started with Addins

Before you get started, you will need to have Android Studio installed.

Start Android Studio and create a new project. Choose the "No Activity" template from the "Phone and Tablet" section of the following menu:New Project

We will name the new project "MyKioWareAddin", and set the Minimum SDK to API 21: Android 5.0 (Lollipop) in the next menu:

Target Device

KioWare addins are Android libraries, so the next step is to convert the generated project to a library instead of an application. In the app.gradle file, remove the applicationId line and change apply plugin: 'com.android.application' to apply plugin: 'com.android.library'

Library

The next step is to include the KioWare addin library as a dependency for the new project. Copy the kiowareaddinlib.jar file to your project's libs folder located at C:\Projects\MyKioWareAddin\app\libs. Replace Projects with the path to the MyKioWareAddin directory.

Dependency

Next we will create a new Java class called "Main". Right click on "com.example.mykiowareaddin" and create a new Java class.


Copy the code below into the Main class.


package com.mykiowareaddin; 

import ... 

public class Main implements IKioWareAddin, IKioWareSessionEvents { 
	 private IKioWareHost mKWHost = null; 

	 @Override 
	 public void setKioWareHost(IKioWareHost host) { mKWHost = host; } 

	 @Override 
	 public IJavascriptInterface[] getJavascriptInterfaces() { return new IJavascriptInterface[0]; } 

	 @Override 
	 public void destroy() { mKWHost = null; } 

	 @Override 
	 public void onLoad() { 
		 Log.i("KioWare", "MyKioWareAddin loaded."); 
		 mKWHost.showToastMessage("MyKioWareAddin loaded.", false); 
	 } 

	 @Override 
	 public void onExit() { Log.i("KioWare", "Exiting KioWare laoded."); } 

	 @Override 
	 public void onSessionStart(UUID sessionId) { Log.i("KioWare", "Session started: " + sessionId); } 

	 @Override 
	 public void onSessionEnd() { Log.i("KioWare", "Session ended."); } 
}

Hover over the classes that have missing dependencies, and press alt+enter to help import the requried libraries.

The Main class implements the IKioWareAddin and IKioWareSessionEvents interfaces. It uses the setKioWareHost() method to get a reference to the KioWare host and sets this host back to null when the addin is destroyed. For each of the session events, a message is logged to the Android console. In the onLoad() method, the KioWare host is used to show a toast message.

To install the addin, first build the project. Once the build has completed, execute the following commands within the Android Studio terminal, replacing "user" with your username:

cd app\build\intermediates\aar_main_jar\debug
C:\Users\user\AppData\Local\Android\sdk\build-tools\30.0.0\dx.bat --dex --output=mykiowareaddin.dex classes.jar

You may need to update the path to the dx.bat file depending on the sdk platforms you installed with Android Studio.

This will create a file called mykiowareaddin.dex within the C:\Projects\MyKioWareAddin\app\build\intermediates\bundles\debug folder. Transfer this file to an Android device with KioWare installed. Save the file under /sdcard/Android/data/com.adsi.kioware.client.mobile.app/Addins. Then enter the KioWare Config app and select the "Addin Management" tab. Click the checkbox next to the addin to enable it.

Enable Addin

The next time you launch KioWare, a toast message should appear when the addin has been loaded.

Toast