iLocky Android SDK

  1. Import iLocky.jar into your android lib directory
  1. AndroidManifest.xml
  1. 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.RECEIVE_BOOT_COMPLETED” />
  1. add iLocky receiver
  • <receiver android:name=”com.ilocky.lock.ILockyReceiver” android:exported=”true” android:enabled=”true”>
  •     <intent-filter>
  •         <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” />
  •     </intent-filter>
  • </receiver>
  1. add iLocky service
  • <service android:name=”com.ilocky.lock.ILockyService”/>
  1. iLocky SDK needs mixpanel SDK, please install mixpanel SDK from https://mixpanel.com/help/reference/android or you can quickly add in your build.gradle file:
  •     dependencies {
  •     compile “com.mixpanel.android:mixpanel-android:4.6.3”
  • }
  1. MainActivity
  1. initialize iLocky SDK
  • @Override
  • protected void onCreate(Bundle savedInstanceState) {
  •     super.onCreate(savedInstanceState);
  •     setContentView(R.layout.activity_main);
  •     ILockyPassport.initialize(this); //initialize the iLocky Passport(Keys)
  •     startService(new Intent(getBaseContext(), ILockyService.class));
  •     doBindService();
  1. doBindService() and doUnBindService()
  •    void doBindService() {
  •      boolean bound = bindService( new Intent( this, ILockyService.class ), serviceConnection, Context.BIND_AUTO_CREATE );
  •         if ( bound ) {
  •             new Handler().postDelayed(new Runnable() {
  •                 @Override
  •                 public void run() {
  •                     myService.setDoInBackground(true); // the iLocky service will run in background during the app open.
  •                     myService.setBackgroundSound(R.raw.open); //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” );
  •         }
  •     }
  •     //doUnbindService
  •     void doUnbindService() {
  •         unbindService(serviceConnection);
  •     }
  •     //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;
  •     }
  • };
  1. onResume(), onPause(), and onDestroy() in MainActivity
  • @Override
  • protected void onResume() {
  •     super.onResume();
  •     SharedPreferences prefs = getSharedPreferences(“iLocky”, Context.MODE_PRIVATE);
  •     doInBackground=prefs.getBoolean(ILockyService.PREFS_DO_IN_BACKGROUND,true);
  •     if(myService!=null)
  •         myService.setDoInBackground(true);
  • }
  • @Override
  • protected void onPause() {
  •     super.onPause();
  •     SharedPreferences prefs = getSharedPreferences(“iLocky”, Context.MODE_PRIVATE);
  •     prefs.edit().putBoolean(ILockyService.PREFS_DO_IN_BACKGROUND,doInBackground).apply();
  •     if(myService!=null) {
  •         myService.setDoInBackground(doInBackground);  // will keep doinbackground setting in service
  •     }
  • }
  • @Override
  • protected void onDestroy() {
  •     super.onDestroy();
  •     doUnbindService();
  • }
  1. when request passport from global server(iLocky team will get done it), you will need to know the uuid of user’s smart phone. you can get it from the following code:
  • ILockyPassport.getDeviceUuid()
  1.  it will return the uuid string. you can send the uuid string to your local server for the requesting passport usage from global server.
  1. you can simply import the passport(key) into this app by
  • try {
  •     ILockyPassport.importPassport(p);
  • } catch (ILockyPassport.ImportPassportException e) {
  •     e.printStackTrace();
  • }
  1. p is the String format, the local server can directly pass the passport file from global server to this method.
  1. 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.
  1. you don’t need to handle any bluetooth handshaking things, the iLocky service will do it for you.
  1. you can use the broadcast receiver to get notification when the key is used and success/fail to handshaking.(will be announced later)
  1. 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 using this app.
  • ILockyBLEManager iLockyBLEManager=new ILockyBLEManager(this,”main”);
  • if(!iLockyBLEManager.isBluetoothON()) {
  •         Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
  •         startActivity(enableBtIntent);
  • }
  1. if use Proguard, please add keep options in proguard-rules.pro
  • -keep class com.mixpanel.android.abtesting.** { *; }
  • -keep class com.mixpanel.android.mpmetrics.** { *; }
  • -keep class com.mixpanel.android.surveys.** { *; }
  • -keep class com.mixpanel.android.util.** { *; }
  • -keep class com.mixpanel.android.java_websocket.** { *; }
  • -keepattributes Signature
  • -dontwarn org.apache.http.**
  • -dontwarn com.google.android.gms.**
  • -keepattributes InnerClasses
  • -keep class **.R
  • -keep class **.R$* {
  • <fields>;
  • }

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Painless Upgrade Your RFID Door Lock

%d bloggers like this: