Baran
Baran

Reputation: 394

Can not run Wifi and Bluetooth scans in background with Flutter

I am working on a part of an indoor localization project. I need my Flutter application scan and get Mac addresses and RSSI values of Wifi and Bluetooth devices. I am using flutter_blue for bluetooth scans and wifi_scan for Wifi scans. The application works well while in the foreground but scans are failing when the application is in background.

What I have tried so far:

Is there any way to achieve this? Aren't there any package with the option backgroundMode: true? I don't know the natives. Don't know Kotlin too.

Upvotes: 1

Views: 1432

Answers (2)

Baran
Baran

Reputation: 394

After a lot of things have been tried, I just tried to get GPS location too.

Used this package: location

And execute location.enableBackgroundMode(enable: true) as it is stated in readme, then my wifi and bluetooth scans starts working in background too.

It's Ridicoulus

Upvotes: 0

TarHalda
TarHalda

Reputation: 1141

According to the Android Developer documentation, ScanMode.lowPower is the only possible mode for background scanning. You also need to request location access for the background (documentation here and here).

Consider switching to Flutter Blue Plus instead of Flutter Blue; Flutter Blue Plus is the currently-maintained version. This pull request on GitHub shows that Flutter Blue cannot run in the background. The pull request has never been merged.

Upvotes: 1

Related Questions