Android Programming Press on the image to return to the main documentation page.

BLE2

List of types:

BleManager2

BleManager2

This library replaces the BLE library. It allows you to search for and connect to BLE devices.
It is supported by Android 4.3+ (API 18).

Permissions:

android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN

Events:

StateChanged (State As Int)
DeviceFound (Name As String, DeviceId As String, AdvertisingData As Map, RSSI As Double)
Disconnected
Connected (Services As List)
DataAvailable (ServiceId As String, Characteristics As Map)
WriteComplete (Characteristic As String, Status As Int)
RssiAvailable (Success As Boolean, RSSI As Double)
MtuChanged (Success As Boolean, MTU As Int)

Members:


  Connect (DeviceId As String)

  Connect2 (DeviceId As String, AutoConnect As Boolean)

  Disconnect

  GetCharacteristicProperties (Service As String, Characteristic As String) As Int

  GetRecordsFromAdvertisingData (AdvertisingData As Map, Key As Int) As List

  Initialize (EventName As String)

  ReadData (Service As String)

  ReadData2 (Service As String, Characteristic As String)

  ReadRemoteRssi

  RequestMtu (MTU As Int) As Boolean

  Scan (ServiceUUIDs As List)

  Scan2 (ServiceUUIDs As List, AllowDuplicates As Boolean)

  SetIndication (Service As String, Characteristic As String, Notify As Boolean) As Boolean

  SetNotify (Service As String, Characteristic As String, Notify As Boolean) As Boolean

  State As Int [read only]

  STATE_POWERED_OFF As Int

  STATE_POWERED_ON As Int

  STATE_UNSUPPORTED As Int

  StopScan

  WriteData (Service As String, Characteristic As String, Data() As Byte)

Members description:

Connect (DeviceId As String)
Connects to a device with the given id. You can only connect to previously discovered devices.
Note that the Disconnected event will be raised if the connection has failed.
Connect2 (DeviceId As String, AutoConnect As Boolean)
Similar to Connect. Allows you to disable auto connection.
Disconnect
GetCharacteristicProperties (Service As String, Characteristic As String) As Int
Returns a numeric value from which you can find the properties of the specified characteristic.
GetRecordsFromAdvertisingData (AdvertisingData As Map, Key As Int) As List
Returns a List with all the records with the specified type.
This is useful when there could be several records with the same type.
Each item in the list is an array of bytes.
Initialize (EventName As String)
Initializes the object. The StateChanged event will be raised after this method with the current BLE state.
ReadData (Service As String)
Asynchronously reads all characteristics from the given service. The DataAvailable will be raised when the data is available.
ReadData2 (Service As String, Characteristic As String)
Asynchronously reads the value of the specified characteristic.
The DataAvailable will be raised when the data of this characteristic is available.
ReadRemoteRssi
Reads the RSSI value of a connected device. The RssiAvailable event will be raised when the value is available.
RequestMtu (MTU As Int) As Boolean
Requests to change the MTU size (packet size). The MtuChanged event will be raised.
Should be called after a connection is established.
Returns True if the request was sent successfully.
Only available on Android 5+. Does nothing on older versions.
Scan (ServiceUUIDs As List)
Starts scanning for devices. The DeviceFound event will be raised when a device is found.
ServiceUUIDs - A list (or array) with service uuids. Devices that don't advertise these uuids will not be discovered.
Pass Null to discover all devices.
Scan2 (ServiceUUIDs As List, AllowDuplicates As Boolean)
Similar to Scan. If AllowDuplicates is true then the DeviceFound event will be raised whenever a packet is received.
SetIndication (Service As String, Characteristic As String, Notify As Boolean) As Boolean
Similar to SetNotify. Sets the descriptor value to 2 (indication) instead of 1 (notification).
Returns True if successful.
SetNotify (Service As String, Characteristic As String, Notify As Boolean) As Boolean
Adds or removes a notification listener that monitor value changes.
The DataAvailable event will be raised when the value of the characteristic changes.
Returns True if successful.
Service - The service id (as returned in the Connected event).
Characteristic - The characteristic id.
Notify - True to add a listener, false to remove it.
State As Int [read only]
Returns the current Bluetooth adapter state.
STATE_POWERED_OFF As Int
STATE_POWERED_ON As Int
STATE_UNSUPPORTED As Int
StopScan
Stops scanning for new devices.
WriteData (Service As String, Characteristic As String, Data() As Byte)
Writes the data to the specified characteristic.
Top