iLocky Android SDK Usage Manual

This article will teach you how to integrate our iLocky SDK into your app.

update message:

  1. v1.0:  SDK supports foreground mode usage in this version. The developer can bypass background code if foreground mode is only considered in your project.


Import iLocky.aar into your project

  • File->New-> New Module -> import .JAR/AAR Package, and select iLocky-sdk.aar
  •  add iLocky-SDK, animation sdk, and mixpanel sdk dependencies in app gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ''

compile ''
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1@aar'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
compile project(':ilocky-sdk')

In AndroidManifest.xml (Foreground)

use SDK in foreground mode:

  • uses-permission
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.CAMERA"/>
  • add iLocky acrtivity
<activity android:name="com.ilocky.ILockyActivity" 
android:launchMode= "singleTop">


In AndroidManifest.xml (Background)

if background access is needed, please add additional code in AndroidManifest.xml :

  • uses-permission
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  • add iLocky receiver
<receiver android:name="com.ilocky.ILockyReceiver" android:exported="true" android:enabled="true">
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        <action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
        <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
        <category android:name="android.intent.category.DEFAULT" />
  • add iLocky service
<service android:name="com.ilocky.ILockyService"/>

MainActivity (Foreground mode)

  • initialize iLocky SDK
protected void onCreate(Bundle savedInstanceState) {
ILockyPassport.initialize(this); //initialize the iLocky Passport(Keys)
  • set language(optional)

iLocky SDK will automatically detect OS language and display the corresponding message in foreground dialog. The developer can manually change the displayed language by using following code setting*.


Only three languages, English, Traditional Chinese, and Simplified Chinese, are supported. If another language is setting. SDK will use English.

* caution: change the iLocky SDK language will also affect your app language. We suggest developer to directly modify your app default language.

  • start ILockyActivity when user intend to access iLocky Device
startActivityForResult(new Intent(MainActivity.this, ILockyActivity.class),0);

you should see the dialog in your app when start iLocky activity:


developer can get the status if user successfully accesses iLocky device through


MainActivity (Background mode)

  • initialize iLocky SDK
protected void onCreate(Bundle savedInstanceState) {
ILockyPassport.initialize(this); //initialize the iLocky Passport(Keys)
startService(new Intent(getBaseContext(), ILockyService.class));
  • doBindService() and doUnBindService()
ILockyService myService=null;
boolean bound=false;
void doBindService() {
boolean bound = bindService( new Intent( this, ILockyService.class ), serviceConnection, Context.BIND_AUTO_CREATE );
if ( bound ) {
new Handler().postDelayed(new Runnable() {
public void run() {
myService.setDoInBackground(true); // the iLocky service will run in background during the app open.
myService.setBackgroundSound(; //set background open door sound(raw resource sound id)
myService.setNotCloseEnoughVibrateAndSound(true,R.raw.notclose);//set not close enough vibrate and sound (true/false for vibrate, not close engough of raw resource sound id)
}, 1000); // not run immdeiately , delay 1 sec to set this service.
else {
Log.d( TAG, "Failed to bind service" );
void doUnbindService() {
//Service Connection
private final ServiceConnection serviceConnection = new ServiceConnection() {
public void onServiceConnected( ComponentName className, IBinder service ) {
myService = ( (ILockyService.ServiceBinder) service ).getService();
bound = true;
public void onServiceDisconnected( ComponentName className ) {
myService = null;
bound = false;
  • onResume(), onPause(), and onDestroy() in MainActivity
protected void onResume() {
SharedPreferences prefs = getSharedPreferences("iLocky", Context.MODE_PRIVATE);
protected void onPause() {
SharedPreferences prefs = getSharedPreferences("iLocky", Context.MODE_PRIVATE);
if(myService!=null) {
myService.setDoInBackground(doInBackground); // will keep doinbackground setting in service
protected void onDestroy() {

Get smart phone’s UUID

when request passport from global server, you will need to know the uuid of user’s smart phone. you can get it from the following code:
it will return the uuid string. you can send the uuid string to your local server for the requesting passport usage from global server.

Import iLocky passport(key)

you can simply import the passport(key) into this app by
try {
} catch (ILockyPassport.ImportPassportException e) {
p is the String format, the local server can directly pass the passport file from global server to this method.
there are iLocky_id, a duration(start and end time), times limit in the the passport(key). You only need to import into our sdk. don’t need to do key setting in app.
you don’t need to handle any bluetooth handshaking things, the iLocky service will do it for you.

iLocky Event callback(In Background Mode)

You can do the extra tasks when passport(key) is successfully used, is failure to use(BLE connection error), or not close enough between iLocky device and smart phone. Set the event callback for ILockyService, e.g.
myService.setILockyEventCallback(new ILocky.ILockyEventCallback() {
public void onDeviceUnauthorized() {

public void onPassportUsed(final ILockyPassport iLockyPassport) {


public void onILockyAccessSuccess(ILockyPassport iLockyPassport) {

public void onILockyAccessFail(ILockyPassport iLockyPassport) {

public void onNotCloseEnough() {

Check Bluetooth status

check bluetooth is turned on or not, if not, ask user to turn on bluetooth. you can add the following code in onResume() to make sure user’s phone BT is turned on when running this app.
if(!bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);


if use Proguard, please add keep options in
-keep class** { *; }
-keep class** { *; }
-keep class** { *; }
-keep class** { *; }
-keep class** { *; }
-keep class com.daimajia.easing.** { *; }
-keep interface com.daimajia.easing.** { *; }

-keep class com.facebook.** { *; }
-keepattributes Signature
-dontwarn org.apache.http.**
-keepattributes InnerClasses

-keep class **.R
-keep class **.R$* {

3 thoughts on “iLocky Android SDK Usage Manual”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s