STWBLEManager

open class STWBLEManager

STWBLEManager

Description :

This class represent the API for all actions/event related to BLE(Bluetooth Low Energy)

This class offers several possible operations defined in the following list :

  • Start Scan : to receive list of available BLE device BleDevice
  • Stop Scan : to stop scan
  • Connect : to Connect to specific device BluetoothDevice
  • Disconnect : to disconnect from current connected device.

This class offers also the possibility to listen for any events related to BLE.

Example of use :

  • To add the Support of "swhardware" module to your project, include the following line in the dependencies block of your build.gradle file:
     
    
     dependencies {
          implementation project(':swhardware')
     }
    
  • 
            STWBLEManager.getInstance().registerBluetoothConnexionStatusChanged(getContext(),
            new IBluetoothLEConnectionStatusChanged() {
    
         public void onConnectionStatusChanged() {
    //Code...
         }
    
         public void onIterateGattServices() {
    //Code...
         }
    
         public void onBLEConnectionStopped() {
    //Code...
         }
    
         public void onBLEConnectionSuccess() {
    //Code...
         }
         });
    
  • 
            STWBLEManager.getInstance().unregisterBluetoothLEStatusChanged(context);
    
  • 
            STWBLEManager.getInstance().registerBleEventChanged(context, new IBleEventCallBack() {
    
         public boolean shouldHandleActions() {
    //Code...
         }
    
         public void onButtonPressed() {
    //Code...
         }
    
         public void onButtonReleased() {
    //Code...
         }
    
         public void onPressPTT1() {
    //Code...
         }
         public void onReleasePTT1() {
    //Code...
         }
    
         public void onPressPTT2() {
    //Code...
         }
    
         public void onReleasePTT2() {
    //Code...
         }
    
         public void onSwitchNext() {
    //Code...
         }
    
         public void onSwitchPrevious() {
    //Code...
         }
    
         public void onPressMBF() {
    //Code...
         }
    
         public void onLongClickMBF() {
    //Code...
         }
    
         public void onPressSOS() {
    //Code...
         }
    
         public void onReleaseSOS() {
    //Code...
         }
    
         });
    
  • 
            STWBLEManager.getInstance().unregisterBleEventChanged(IBleEventCallBack);
    

Properties

Link copied to clipboard
open val BATTERY_LEVEL_ZERO: Int
Link copied to clipboard
val SCAN_FAILED_BLUETOOTH_IS_NOT_ENABLED: Int
can not perform a scan if the location permission not granted
Link copied to clipboard
val SCAN_FAILED_FEATURE_UNSUPPORTED: Int
can not perform a scan if the location permission not granted
Link copied to clipboard
val SCAN_FAILED_LOCATION_DISABLED: Int
can not perform a scan if the system location is disabled
val SCAN_FAILED_LOCATION_PERMISSION_NOT_GRANTED: Int
can not perform a scan if the location permission not granted
Link copied to clipboard
val SCAN_FAILED_NO_DEVICE_FOUND: Int
Scan terminated an no device was found

Functions

Link copied to clipboard
open fun abortCurrentLeScan(@NonNull context: Context)
Abort current scan, the disconnects an established connection.
Link copied to clipboard
open fun addAccessoriesName(@NonNull accessoriesName: String, @NonNull bleDeviceHandler: BleDeviceHandler)
Link copied to clipboard
open fun addServiceUUID(@NonNull serviceUUId: UUID, @NonNull bleDeviceHandler: BleDeviceHandler)
Called to add New BLE Device.
Link copied to clipboard
open fun checkConnectedDevices(@NonNull context: Context)
At first login check if there is a connected Bluetooth device to update local connected device to automatically redirect Audio to connected device
Link copied to clipboard
open fun connect(@NonNull context: Context, @Nullable device: BluetoothDevice): Boolean
open fun connect(@NonNull context: Context, @Nullable deviceAddress: String): Boolean
Called to connect to the GATT server hosted on the Bluetooth LE device.
Link copied to clipboard
open fun connectIfAvailable(    @NonNull context: Context,     @NonNull address: String,     scanPeriod: Int)
Start scan for BleDevices
Link copied to clipboard
open fun disconnect(@NonNull context: Context)
open fun disconnect(@Nullable context: Context, @Nullable address: String): Boolean
Disconnects an existing connection or cancel a pending connection.
Link copied to clipboard
open fun getBatteryLevel(): Int
Call this method to retrieve the battery level
Link copied to clipboard
open fun getBluetoothAdapter(@NonNull context: Context): BluetoothAdapter
Call this method to retreive the Bluetooth adapter instance
Link copied to clipboard
open fun getConnectedBleDeviceHandler(): BleDeviceHandler
Called to get the connected BleDeviceHandler
Link copied to clipboard
open fun getConnectedBluetoothDevice(): BluetoothDevice
Called to get the connected BluetoothDevice
Link copied to clipboard
open fun getInstance(): STWBLEManager
Link copied to clipboard
open fun isAinaDeviceConnected(): Boolean
Called to check if connected device is Aina.
Link copied to clipboard
open fun isBLEDeviceType(@NonNull bluetoothDevice: BluetoothDevice): Boolean
Check the type of device if is BLE type.
Link copied to clipboard
open fun isBLESupported(@NonNull context: Context): Boolean
Check if BLE is supported.
Link copied to clipboard
open fun isBluetoothAdapterEnabled(@NonNull context: Context): Boolean
Call this method to check if the bluetooth adapter is enabled
Link copied to clipboard
open fun isBluetoothLEScanAllowed(@NonNull context: Context): Boolean
Called to check if Bluetooth Scan is allowed.
Link copied to clipboard
open fun isConnected(): Boolean
Called to check if current connection status is STATE_CONNECTED.
Link copied to clipboard
open fun isConnecting(): Boolean
Called to check if current connection status is STATE_CONNECTING.
Link copied to clipboard
open fun isHeadsetOrBluetoothAvailable(@NonNull context: Context, @NonNull audioManager: AudioManager): Boolean
Called to check if there is a connected headset or Bluetooth.
Link copied to clipboard
open fun isScanning(): Boolean
Called to check if there is a current scan.
Link copied to clipboard
open fun isSupportedDevice(): Boolean
Called to check if current connected device is supported.
Link copied to clipboard
open fun registerBatteryLevel(@NonNull batteryLevelChanged: IBatteryLevelChanged)
Call this method to be notifiyed when the aina battery level is changed
Link copied to clipboard
open fun registerBleEventChanged(@NonNull bleEventCallBack: IBleEventCallBack)
Register the specified callback to be notified by BLE events
Link copied to clipboard
open fun registerBluetoothConnexionStatusChanged(@NonNull bluetoothLEConnexionStatusChanged: IBluetoothLEConnectionStatusChanged)
Register the specified callback to be notified by BLE connection status.
Link copied to clipboard
open fun scanLeDevices(    @NonNull context: Context,     scanPeriod: Int,     @NonNull swLeScanCallback: ISWLeScanCallback)
Start scan for Ble Devices BleDevice.
Link copied to clipboard
open fun setScanCallback(@NonNull scanCallback: IScanCallback)
Link copied to clipboard
open fun setServiceListener(@Nullable serviceListener: IServiceListener)
Link copied to clipboard
open fun unRegisterBatteryLevel(@NonNull batteryLevelChanged: IBatteryLevelChanged)
Call this method to unregister from battery level
Link copied to clipboard
open fun unregisterBleEventChanged(@NonNull bleEventCallBack: IBleEventCallBack)
Unregister the specified callback to not receive any more the BLE events.
Link copied to clipboard
open fun unregisterBluetoothLEStatusChanged(@NonNull bluetoothLEConnectionStatusChanged: IBluetoothLEConnectionStatusChanged)
Unregister the specified callback to not receive BLE connection status event again.