I would like to start a continuous search for bluetooth devices in the background and send a notification when a device "X" is detected.
At this moment I run a periodic timer every 5 seconds, in which I perform a new scan
How can I do this scan even if I turn off the application?
Timer.periodic(Duration(milliseconds: 5000), (timer) => discovery());
void discovery() {
var tmp = new Map<String, BluetoothDevice>();
FlutterBluetoothSerial.instance.startDiscovery().listen((r) {
tmp.putIfAbsent(r.device.address, () => r.device);
app.onDiscovery(r);
}).onDone(() {
_isDiscovering = false;
});
}
I would like a solution compatible with IOS and Android.
Thank you and good day.