Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanned multiple device (same UUID) on Android #603

Open
fahami opened this issue Jun 28, 2021 · 0 comments
Open

Scanned multiple device (same UUID) on Android #603

fahami opened this issue Jun 28, 2021 · 0 comments

Comments

@fahami
Copy link

fahami commented Jun 28, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant