'Flutter app with BLE and geolocation updates in foreground and backgroud

I have to build a flutter app that:

  • receive data from a BLE device
  • add geolocation info

My major concern is on how to keep receiving both data even when the user receives a call, switch to a different app or the screen simply turns off. I have to build a service in native code (Swift, Kotlin) that keeps the flutter app always running? Is there a way to keep flutter always in the foreground and show only toast notifications?

The flutter package geolocation seems to work even in background simple using:

StreamSubscription<LocationResult> subscription = Geolocation.locationUpdates(
    accuracy: LocationAccuracy.best,
    displacementFilter: 10.0, // in meters
    inBackground: true, // by default, location updates will pause when app is inactive (in background). Set to `true` to continue updates in background.
  )
  .listen((result) {
    if(result.isSuccessful) {
      // todo with result
    }
  });


// cancelling subscription will also stop the ongoing location request
subscription.cancel();

But how to keep receiving BLE data?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source