Skip to content

BLEDeviceManager

A device manager for a Bluetooth Low Energy (BLE) device.

E.g. a heart rate monitor. The app finds the device (e.g., by scanning) and calls pair with its BLE address before connecting. The BLE address and name are also taken from the registration, if any. Bluetooth permissions are checked and asked for; on Android this includes location.

Inheritance

Constructors

BLEDeviceManager

BLEDeviceManager<TDeviceConfiguration extends BLEDevice<TRegistration>, TRegistration extends BLEDeviceRegistration>(
  1. String deviceType, {
  2. TDeviceConfiguration? configuration,
})

Properties

bleAddress

String? bleAddress
getter/setter pair

The BLE address of this device.

The format of the BLE address is platform-specific. On Android, it is typically a MAC address of the form 00:04:79:00:0F:4D. On iOS, it is typically be a UUID string on the form E2C56DB5-DFFB-48D2-B060-D0F5A71096E0.

Returns null if unknown. Typically, the BLE address is only known after pairing with a specific BLE device.

bleName

String? bleName
getter/setter pair

The BLE name of this device, if known.

displayName

String? get displayName
override

Default display name for a BLE device is its BLE name or address.

manufacturerData

List<int> manufacturerData
getter/setter pair

Manufacturer specific data. The first 2 bytes are the Company Identifier Codes.

serviceUuids

List<String> serviceUuids
getter/setter pair

Advertised services of this device, if known.

Methods

onConfigure

void onConfigure()
override

Callback on configure.

When called, the configuration and the registration is available.

Is to be overridden in sub-classes. Note, however, that it must not be doing a lot of work on startup.

onHasPermissions

Future<bool> onHasPermissions()
override

Callback on hasPermissions.

Can be overridden in sub-classes for device-specific permission handling.

onPaired

bool onPaired()

Called by pair after the BLE device information is set.

Returns true if pairing succeeded. By default, pairing always succeeds; override for device-specific pairing.

onRequestPermissions

Future<void> onRequestPermissions()
override

Callback on requestPermissions.

Can be overridden for device-specific permission handling.

pair

void pair({
  1. required String bleAddress,
  2. String? bleName,
  3. List<String>? serviceUuids,
  4. List<int>? manufacturerData,
})

Pairs this device manager with the BLE device at bleAddress.

Optionally sets its bleName, serviceUuids, and manufacturerData. Sets status to DeviceStatus.paired if onPaired returns true.