scanForDevices method

Stream<DiscoveredDevice> scanForDevices({
  1. required List<Uuid> withServices,
  2. ScanMode scanMode = ScanMode.balanced,
  3. bool requireLocationServicesEnabled = true,
})

Scan for BLE peripherals advertising the services specified in withServices or for all BLE peripherals, if no services is specified. It is recommended to always specify some services.

There are two Android specific parameters that are ignored on iOS:

  • scanMode allows to choose between different levels of power efficient and/or low latency scan modes.
  • requireLocationServicesEnabled specifies whether to check if location services are enabled before scanning. When set to true and location services are disabled, an exception is thrown. Default is true. Setting the value to false can result in not finding BLE peripherals on some Android devices.

Implementation

Stream<DiscoveredDevice> scanForDevices({
  required List<Uuid> withServices,
  ScanMode scanMode = ScanMode.balanced,
  bool requireLocationServicesEnabled = true,
}) async* {
  await initialize();

  yield* _deviceScanner.scanForDevices(
    withServices: withServices,
    scanMode: scanMode,
    requireLocationServicesEnabled: requireLocationServicesEnabled,
  );
}