Class Blukii

java.lang.Object
com.blukii.sdk.config.Blukii
Direct Known Subclasses:
SmartBeacon, SmartKey

public class Blukii extends Object
This class represents a blukii device and is the main controller class for connection based communication with blukii devices.

Blukii is the single point of contact for all actions that are provided by blukii GATT profiles.

Quick start documentation

blukii types

This class contains all blukii functions that are independent of any blukii type.

For each blukii type there is a derived class that contains additional type specific functions:

Get blukii device object

Initially, you need a valid blukii device (BluetoothDevice) to connect to. You have to search for BLE devices what can easily be done by the BlukiiClient class, which is part of the library's info package.

You can retrieve a BluetoothDevice object by calling DiscoveryData.getDevice().

Connect & Disconnect

This class provides methods to connect to a blukii device and disconnect from it. So you can call connect(ConnectionListener) to initiate the connection and you can call disconnect() if your work is done and you want to free your device.

You can keep track about the connection state via the ConnectionListener interface which is handed to the Blukii class via the connect(ConnectionListener) method.

Example snippet


 private boolean connectDevice() {
   // get blukii device object from an OutputElement, that is retrieved
   // from BlukiiClient.OnDiscoveryListener
   BluetoothDevice bluetoothDevice = outputElement.getDiscoveryData().getDevice();

   // create new Blukii instance (see also BlukiiController)
   mBlukii = BlukiiController.getInstance().getNewSmartBeaconConfig(bluetoothDevice);

   // initiate connection => retrieve callback via ConnectionListener
   mBlukii.connect(mConnectionListener);
 }

 private final ConnectionListener mConnectionListener = new ConnectionListener() {
   @Override
   public void onConnected() {
     // Connection successful
   }

   @Override
   public void onDisconnected(DisconnectReason reason) {
       // Device is disconnected or connection failed
   }

   // ...

 });
 

Asynchronous requests

This class contains a large set of requests that are supported by the several blukii devices.

Important: all requests are called asynchronously. The results are returned via callbacks of ResponseListener.

Via ResponseListener.onResponse(ResponseData) you get the value if the call was successful. Otherwise you get an Error via the ResponseListener.onError(ResponseError) callback.

Each method gets a ResponseListener object to provide the callable callback methods ResponseListener.onResponse(ResponseData), ResponseListener.onError(ResponseError) and ResponseListener.onNotify(ResponseData).

Example Snippet


 private void readTxPower() {
   mBlukii.readTxPower(new ResponseListener() {
     @Override
     onResponse(ResponseData response) {
       int txPower = response.getData().getDeviceValue();
       Log.i(TAG, "Read TxPower Success: " + txPower);
     }

     @Override
     onError(ResponseError error) {
       Log.e(TAG, "Read TxPower Error: + error.getErrorStatus());
     }

     @Override
     onNotify(ResponseData response) {}
   }
 }

 private void writeIBeacon(UUID uuid, int major, int minor) {
   IBeacon iBeaconData = new IBeacon();
   iBeaconData.setUUID(uuid);
   iBeaconData.setMajor(major);
   iBeaconData.setMinor(minor);

   mBlukii.writeIBeaconAdvertising(iBeaconData, new ResponseListener() {
     @Override
     onResponse(ResponseData response) {
       IBeacon iBeaconData = response.getData().getDeviceValue();
       Log.i(TAG, "Write iBeacon Success");
     }

     @Override
     onError(ResponseError error) {
       Log.e(TAG, "Write iBeacon Error: " + error.getErrorStatus());
     }

     @Override
     onNotify(ResponseData response) {}
   }
 }
 

Cloud support

You can interact with blukii Manager for retrieving cloud managed data and synchronizing device data to cloud.

This sdk feature requires an authentication via the BlukiiCloud class:

See also DataManager class for managing cloud dependent data.