Getting Started with Addins

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

Start Android Studio and create a new project. We will name the new project "MyKioWareAddin".

New Project

Choose "Phone and Tablet" with a minimum SDK of 14 from the following screen.

Target Device

Select "No Activity" and click "Finish" to create the project.

No Activity

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\test\MyKioWareAddin\app\libs. Replace projects\test with the path to the MyKioWareAddin directory.

Dependency

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


Main

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("MKioWareAddin loaded.", false); 
	 } 

	 @Override 
	 public void onExit() { Logi("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."); } 
}

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\bundles\debug
C:\Users\user\AppData\Local\Android\sdk\build-tools\26.0.0\dx.bat --dex --output=mykiowareaddin.dex classes.jar

This will create a file called mykiowareaddin.dex within the C:\projects\test\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