public class KontaktDeviceConnection extends java.lang.Object implements IKontaktDeviceConnection
All operation with device should be as quick as possible. You should not open connection and wait long time before taking any action. After doing job connection should be closed immediately
| Modifier and Type | Class and Description | 
|---|---|
| static class  | KontaktDeviceConnection.StateState enum describes all possible state that BeaconConnection may be in. | 
IKontaktDeviceConnection.ConnectionListener| Modifier and Type | Field and Description | 
|---|---|
| static int | ERROR_AUTHENTICATIONError code informing that unexpected error has occured while attempting
 beacon authentication. | 
| static int | ERROR_BATCH_WRITE_INSTANCE_IDError code informing that Batch write operation failed during InstanceId write | 
| static int | ERROR_BATCH_WRITE_INTERVALError code informing that Batch write operation failed during Interval write. | 
| static int | ERROR_BATCH_WRITE_MAJORError code informing that Batch write operation failed during Major write. | 
| static int | ERROR_BATCH_WRITE_MINORError code informing that Batch write operation failed during Minor write. | 
| static int | ERROR_BATCH_WRITE_NAMEError code informing that Batch write operation failed during Name write | 
| static int | ERROR_BATCH_WRITE_NAMESPACEError code informing that Batch write operation failed during Namespace write | 
| static int | ERROR_BATCH_WRITE_PASSWORDError code informing that Batch write failed during Password write | 
| static int | ERROR_BATCH_WRITE_PROFILEError code informing that Batch write operation failed during Profile write | 
| static int | ERROR_BATCH_WRITE_PROXIMITY_UUIDError code informing that Batch write operation failed during Proximity UUID write. | 
| static int | ERROR_BATCH_WRITE_TX_POWERError code informing that Batch write operation failed during Transmission Power write. | 
| static int | ERROR_BATCH_WRITE_URLError code informing that Batch write operation failed during Url write | 
| static int | ERROR_OVERWRITE_REQUESTError code informing that error has occured during characteristic
 overwrite process. | 
| static int | ERROR_SERVICES_DISCOVERYError code informing that Beacon services discovery has failed. | 
| static int | FAILURE_UNKNOWN_BEACONFailure code informing that BLE device was not recognised as kontakt.io
 Beacon. | 
| static int | FAILURE_WRONG_PASSWORDFailure code informing that beacon was not authenticated because of
 wrong password. | 
| Modifier | Constructor and Description | 
|---|---|
|   | KontaktDeviceConnection(Context context,
                       RemoteBluetoothDevice bluetoothDevice,
                       IKontaktDeviceConnection.ConnectionListener connectionListener) | 
| protected  | KontaktDeviceConnection(Context context,
                       RemoteBluetoothDevice bluetoothDevice,
                       IKontaktDeviceConnection.ConnectionListener connectionListener,
                       KontaktDeviceServiceStore serviceStore) | 
| Modifier and Type | Method and Description | 
|---|---|
| void | acceptProfile(IPreset profile,
             WriteBatchListener<IPreset> writeBatchListener)Accepts predefined profile ( Preset) and changes parameters for Beacon. | 
| void | applyConfig(IConfig config,
           WriteBatchListener<IConfig> writeBatchListener)Applies pending configuration ( Config) for Beacon. | 
| void | applySecureConfig(java.lang.String secureConfig,
                 WriteListener writeListener)Method for writing secure config. | 
| void | close() | 
| boolean | connect() | 
| void | enableDfuMode(java.lang.String masterPassword,
             WriteListener writeListener)Enables dfu mode. | 
| void | enableNonConnectableMode(java.lang.String masterPassword,
                        WriteListener writeListener)Changes Beacon mode to non-connectable. | 
| void | executeSecureCommand(java.lang.String secureCommand,
                    WriteListener writeListener) | 
| RemoteBluetoothDevice | getDevice() | 
| static int | getGattError(int errorCode)Method for getting gatt erorr status code from received errorCode | 
| boolean | isAuthenticated() | 
| boolean | isClosed() | 
| boolean | isConnected() | 
| static boolean | isGattError(int errorCode)Metohd for checking is error code indicating GATT error | 
| protected void | overwrite(BluetoothGattCharacteristic characteristic,
         byte[] newValue,
         WriteListener listener) | 
| void | overwriteAdvertisingInterval(long millis,
                            WriteListener writeListener)Changes Beacon advertising interval. | 
| void | overwriteInstanceId(java.lang.String instanceId,
                   WriteListener writeListener)Overwrite instance id. | 
| void | overwriteMajor(int value,
              WriteListener writeListener)Changes Beacon major value. | 
| void | overwriteMinor(int value,
              WriteListener writeListener)Writes minor value. | 
| void | overwriteModelName(java.lang.String newModelName,
                  WriteListener writeListener)Changes Beacon model name. | 
| void | overwriteNamespaceId(java.lang.String namespaceId,
                    WriteListener writeListener)Overwrites namespace id. | 
| void | overwritePassword(java.lang.String newPassword,
                 WriteListener writeListener)Changes beacon password. | 
| void | overwritePowerLevel(int powerLevel,
                   WriteListener writeListener)Changes Beacon power level. | 
| void | overwriteProximityUUID(java.util.UUID proximity,
                      WriteListener writeListener)Changes Beacon Proximity UUID value. | 
| protected void | overwriteSecure(BluetoothGattCharacteristic characteristic,
               byte[] newValue,
               WriteListener listener,
               boolean readResponse) | 
| void | overwriteUrl(java.lang.String newUrl,
            WriteListener writeListener)Overwrites url. | 
| void | resetDevice(WriteListener writeListener)Resets device so that connection is established once again. | 
| void | restoreDefaultSettings(java.lang.String masterPassword,
                      WriteListener writeListener)Restores default Beacon settings. | 
| void | switchToDeviceProfile(DeviceProfile deviceProfile,
                     WriteListener writeListener)Switch to device profile. | 
public static final int ERROR_SERVICES_DISCOVERY
public static final int ERROR_OVERWRITE_REQUEST
public static final int ERROR_AUTHENTICATION
public static final int FAILURE_UNKNOWN_BEACON
public static final int FAILURE_WRONG_PASSWORD
public static final int ERROR_BATCH_WRITE_PROXIMITY_UUID
public static final int ERROR_BATCH_WRITE_TX_POWER
public static final int ERROR_BATCH_WRITE_MAJOR
public static final int ERROR_BATCH_WRITE_MINOR
public static final int ERROR_BATCH_WRITE_INTERVAL
public static final int ERROR_BATCH_WRITE_PROFILE
public static final int ERROR_BATCH_WRITE_NAMESPACE
public static final int ERROR_BATCH_WRITE_INSTANCE_ID
public static final int ERROR_BATCH_WRITE_URL
public static final int ERROR_BATCH_WRITE_NAME
public static final int ERROR_BATCH_WRITE_PASSWORD
public KontaktDeviceConnection(Context context,
                               RemoteBluetoothDevice bluetoothDevice,
                               IKontaktDeviceConnection.ConnectionListener connectionListener)
protected KontaktDeviceConnection(Context context,
                                  RemoteBluetoothDevice bluetoothDevice,
                                  IKontaktDeviceConnection.ConnectionListener connectionListener,
                                  KontaktDeviceServiceStore serviceStore)
public static boolean isGattError(int errorCode)
errorCode - received from IKontaktDeviceConnection.ConnectionListener.onErrorOccured(int)public static int getGattError(int errorCode)
 throws IllegalAccessException if errorCode is not gatt error code
errorCode - public RemoteBluetoothDevice getDevice()
getDevice in interface IKontaktDeviceConnectionpublic boolean connect()
connect in interface IKontaktDeviceConnectionpublic boolean isConnected()
isConnected in interface IKontaktDeviceConnectionpublic boolean isAuthenticated()
isAuthenticated in interface IKontaktDeviceConnectionpublic void close()
close in interface IKontaktDeviceConnectionpublic boolean isClosed()
isClosed in interface IKontaktDeviceConnectionpublic void applyConfig(IConfig config, WriteBatchListener<IConfig> writeBatchListener)
Config) for Beacon.
 
 It is possible to encounter problems during batch (the Config in this case)
 write operation which result in launching error handle callback method.
 Once the write batch operation failes, the Write Batch Processor
 will attempt performing rollback write batch operation aiming at
 restoring original Beacon configuration.
 The rollback operation however may not succeed as well leaving Beacon device
 changed partially.
 Therefore it is strongly advisable to write batches in relatively close distance
 to Beacon device. Thus, the risk of leaving Beacon in unspecified state may
 be avoided.
 
 The method is synchronized.
 
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
applyConfig in interface IKontaktDeviceConnectionconfig - the configwriteBatchListener - the write batch listenerpublic void acceptProfile(IPreset profile, WriteBatchListener<IPreset> writeBatchListener)
Preset) and changes parameters for Beacon.
 
 It is possible to encounter problems during batch (the Preset in this case) write operation which result
 in launching error handle callback method. Once the write batch operation failes,
 the Write Batch Processor will attempt performing rollback write batch
 operation aiming at restoring original Beacon configuration.
 The rollback operation however may not succeed as well leaving Beacon device
 changed partially.
 Therefore it is strongly advisable to write batches in relatively close distance
 to Beacon device. Thus, the risk of leaving Beacon in unspecified state may
 be avoided.
 
 The method is synchronized.
 
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
acceptProfile in interface IKontaktDeviceConnectionprofile - the profilewriteBatchListener - the write batch listenerpublic void overwriteMinor(int value,
                           WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwriteMinor in interface IKontaktDeviceConnectionvalue - the valuewriteListener - the write listenerpublic void enableNonConnectableMode(java.lang.String masterPassword,
                                     WriteListener writeListener)
DeviceCredentials)
 
 The method is synchronized.
 
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
enableNonConnectableMode in interface IKontaktDeviceConnectionmasterPassword - the beacon master passwordwriteListener - the write listenerpublic void overwriteMajor(int value,
                           WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwriteMajor in interface IKontaktDeviceConnectionvalue - new valuewriteListener - the write listenerpublic void overwriteProximityUUID(java.util.UUID proximity,
                                   WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwriteProximityUUID in interface IKontaktDeviceConnectionproximity - the proximity UUIDwriteListener - the write listenerpublic void overwritePassword(java.lang.String newPassword,
                              WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwritePassword in interface IKontaktDeviceConnectionnewPassword - the new passwordwriteListener - the write listenerpublic void overwriteModelName(java.lang.String newModelName,
                               WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwriteModelName in interface IKontaktDeviceConnectionnewModelName - the new model namewriteListener - the write listenerpublic void overwriteAdvertisingInterval(long millis,
                                         WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwriteAdvertisingInterval in interface IKontaktDeviceConnectionmillis - the interval milliswriteListener - the write listenerpublic void overwritePowerLevel(int powerLevel,
                                WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwritePowerLevel in interface IKontaktDeviceConnectionpowerLevel - the power levelwriteListener - the write listenerpublic void switchToDeviceProfile(DeviceProfile deviceProfile, WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
switchToDeviceProfile in interface IKontaktDeviceConnectiondeviceProfile - the device profilewriteListener - the write listenerpublic void resetDevice(WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
resetDevice in interface IKontaktDeviceConnectionwriteListener - the write listenerpublic void enableDfuMode(java.lang.String masterPassword,
                          WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
enableDfuMode in interface IKontaktDeviceConnectionmasterPassword - the master passwordwriteListener - the write listenerpublic void overwriteUrl(java.lang.String newUrl,
                         WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwriteUrl in interface IKontaktDeviceConnectionnewUrl - the new urlwriteListener - the write listenerpublic void overwriteNamespaceId(java.lang.String namespaceId,
                                 WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwriteNamespaceId in interface IKontaktDeviceConnectionnamespaceId - the namespace idwriteListener - the write listenerpublic void overwriteInstanceId(java.lang.String instanceId,
                                WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
overwriteInstanceId in interface IKontaktDeviceConnectioninstanceId - the instance idwriteListener - the write listenerpublic void restoreDefaultSettings(java.lang.String masterPassword,
                                   WriteListener writeListener)
 Throws IllegalOperationException if provided RemoteBluetoothDevice is in version 4.0 or higher
 
restoreDefaultSettings in interface IKontaktDeviceConnectionmasterPassword - the master passwordwriteListener - the write listenerpublic void applySecureConfig(java.lang.String secureConfig,
                              WriteListener writeListener)
 Throws IllegalOperationException if provided device is  below 4.0 firmware version
 
applySecureConfig in interface IKontaktDeviceConnectionsecureConfig - writeListener - public void executeSecureCommand(java.lang.String secureCommand,
                                 WriteListener writeListener)
executeSecureCommand in interface IKontaktDeviceConnectionprotected void overwrite(BluetoothGattCharacteristic characteristic,
                         byte[] newValue,
                         WriteListener listener)
protected void overwriteSecure(BluetoothGattCharacteristic characteristic,
                               byte[] newValue,
                               WriteListener listener,
                               boolean readResponse)