pauldemarco / flutter_blue

Bluetooth plugin for Flutter
BSD 3-Clause "New" or "Revised" License
2.36k stars 1.23k forks source link

Support for background scanning #113

Open wkornewald opened 5 years ago

wkornewald commented 5 years ago

It would be awesome if flutter_blue supported scanning in background, so when a device with certain properties appears the app can be waked up and do some processing in the background. Now Flutter officially supports background execution:

https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124

On Android 8+ background scanning could be based on ScanFilter with PendingIntent. On older Android versions this could use a background task with ScanFilter + callback. A foreground service shouldn't be necessary (though it might be useful in rare cases, e.g. when working with beacons). Some of this is also described in the AltBeacon library: http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8

dude8604 commented 5 years ago

Also being able to be notified when there incoming data from a specific device or from any device.

dude8604 commented 5 years ago

I don't know if it's against the rules to post this. If it is, please delete this comment or tell me to and I will.

I put a $10 bounty on this issue. It's probably not enough, so if anyone else wants to add to the bounty please do.

vinceramcesoliveros commented 5 years ago

There was a plugin for beacons. though It doesn't support background scanning.

fvisticot commented 5 years ago

I would be very interested to have background support for this plugin. Is it in the roadmap (Android only) ?

jifalops commented 5 years ago

I have a use case for this. A customer wants to detect nearby devices with their app installed. Periodically scanning for BLE devices in the background is necessary.

Can anyone comment if https://pub.dartlang.org/packages/beacons is a suitable workaround to enable background scanning for nearby BLE devices?

michaellee8 commented 5 years ago

@jifalops It says monitoring (include background), maybe worth a try?

ebsjruiz commented 5 years ago

Can anyone confirm if flutter is a good solution for background beacon scanning? We are running into a bunch of issues on the newest IOS.

alod2019 commented 4 years ago

There is the fix that should enable background scanning but it's not yet merged, see https://github.com/pauldemarco/flutter_blue/issues/187 https://github.com/pauldemarco/flutter_blue/pull/210

toniree commented 4 years ago

Is this supported as well? "Have a BLE beacon send signals 24/7, and when a phone comes within range, the Beacon fetches data from the phone, while the phone is locked."

gib40f commented 3 years ago

This is a feature that would be very useful to a project we are working on. Would be really good to have the app woken up by a device. I have built the app to do a scan when being brought to the foreground looking for a specific device that has been paired by the user. We are getting some uphill to make this process more seamless.

SantiagoMinian commented 3 years ago

On our case, we only needed to add UIBackgroundModes as stated here in order to continue listening to BLE device updates while the phone was locked or the user had switched to a different app.