Skip to content

Scanned multiple device (same UUID) on Android #603

Open
@fahami

Description

@fahami

I write some code to scan BLE peripheral on background (using android alarm manager) but I had multiple scanned device with same UUID. I want to just get one result per UUID, any solution?

Code:
When code below changed, it will fire a code fireAlarm()

SwitchListTile(
 value: broadcastBLE.isBroadcasting,
 onChanged: (value) async {
   broadcastBLE.isBroadcasting = value;
   value
       ? await AndroidAlarmManager.oneShot(Duration(seconds: 2), 0, fireAlarm)
       : await AndroidAlarmManager.cancel(0);
 },
 title: Text("Aktifkan tracing"),
),

fireAlarm()

void fireAlarm() async {
BleManager bleManager = BleManager();
  await bleManager.createClient();
  try {
    print("Fired at ${DateTime.now()}");
    bleManager.startPeripheralScan(scanMode: ScanMode.lowLatency).listen((scanResult) {
      List parsed = scanResult.advertisementData.manufacturerData;
      if (parsed.length == 26) {
        final parsedSlave = Uuid.unparse(parsed.sublist(10, 26));
        print(parsedSlave);
      }
      Future.delayed(Duration(seconds: 4)).then((value) => bleManager.stopPeripheralScan());
    });
  } catch (e) {
    print(e);
  }
}

and i got duplicated 6 times same uuid "08957263-1010-0000-0000-00010064c570" here

I/flutter ( 4764): Fired at 2021-06-28 18:21:27.321030
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin( 4764): on native side observed method: startDeviceScan
D/BluetoothAdapter( 4764): isLeEnabled(): ON
D/BluetoothLeScanner( 4764): onClientRegistered() - status=0 clientIf=9 mClientIf=0
(6) I/flutter ( 4764): 08957263-1010-0000-0000-00010064c570
(2) D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin( 4764): on native side observed method: stopDeviceScan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions