chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
735 stars 446 forks source link

[Bug]: Cannot retrieve platformName from bondedDevices #631

Closed benderaze closed 11 months ago

benderaze commented 11 months ago

Requirements

Have you checked this problem on the example app?

No

FlutterBluePlus Version

1.17.3

Flutter Version

3.10.6

What OS?

Android

OS Version

10

Bluetooth Module

Don't know

What is your problem?

When getting the bondedDevices, the platformName is always empty. The debug logs are displaying the right platformName, but the returned objects have empty platformName.

This is because the bondedDevices method do not fill the _platformNames like connectedSystemDevices does.

Bellow a working code for bondedDevices: /// Retrieve a list of bonded devices (Android only) static Future<List<BluetoothDevice>> get bondedDevices async { BmConnectedDevicesResponse response = await _invokeMethod('getBondedDevices') .then((args) => BmConnectedDevicesResponse.fromMap(args)); for (BmBluetoothDevice device in response.devices) { if (device.platformName != null) { _platformNames[DeviceIdentifier(device.remoteId)] = device.platformName!; } } return response.devices.map((d) => BluetoothDevice.fromProto(d)).toList(); }

Logs

D/BluetoothAdapter( 2548): STATE_ON
D/BluetoothAdapter( 2548): BLE support array set: 010011
D/BluetoothLeScanner( 2548): Start Scan with callback
D/BluetoothLeScanner( 2548): onScannerRegistered() - status=0 scannerId=14 mScannerId=0
I/flutter ( 2548): [FBP] <startScan> result: true
I/flutter ( 2548): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 2548): [FBP] onMethodCall: getAdapterState
I/flutter ( 2548): [FBP] <getAdapterState> result: {adapter_state: 4}
I/flutter ( 2548): bluetooth state: BluetoothAdapterState.on
I/flutter ( 2548): Bluetooth is on
I/flutter ( 2548): [FBP] <turnOn> args: null
D/[FBP-Android]( 2548): [FBP] onMethodCall: turnOn
I/flutter ( 2548): [FBP] <turnOn> result: true
I/flutter ( 2548): [FBP] <getAdapterState> args: null
D/[FBP-Android]( 2548): [FBP] onMethodCall: getAdapterState
I/flutter ( 2548): [FBP] <getAdapterState> result: {adapter_state: 4}
I/flutter ( 2548): [FBP] <getConnectedSystemDevices> args: null
D/[FBP-Android]( 2548): [FBP] onMethodCall: getConnectedSystemDevices
I/flutter ( 2548): [FBP] <getConnectedSystemDevices> result: {devices: []}
I/flutter ( 2548): [FBP] <getBondedDevices> args: null
D/[FBP-Android]( 2548): [FBP] onMethodCall: getBondedDevices
I/flutter ( 2548): [FBP] <getBondedDevices> result: {devices: [{remote_id: 48:F0:7B:B9:AC:B2, platform_name: XXXXX}]}
I/flutter ( 2548): platformName: 
I/flutter ( 2548): BluetoothDevice{remoteId: 48:F0:7B:B9:AC:B2, platformName: , services: null}
chipweinberger commented 11 months ago

fixed 1.20.2