Zia
Zia

Reputation: 683

Flutter: Listen to location update while the app is minimized if location permission is set to "while using the app"

I'm sorry if this question is duplicate but believe me there is no certain answer to the question How to listen to current location changes while the app is minimized and location permission is set to while using the app in flutter.

There is a same question but not given a solution Current location while in background using GeoLocator

I don't know how other big companies like lyft and Uber handled this problem?

I built a driver app which requires to share driver current location,it works perfectly when the app is in use (not minimized) but the moment user opens another app (my app goes to background) the location update stops.

I used to let drivers set their location permission to always and pushed to production, but drivers are not ok with letting their location accessed all the time.

The packages I used location and permission_handler.

there is part of my code where I listen to lcoation changes

 _listenLocationChanges(address, orderId) async {
    _locSubscription = location.onLocationChanged.listen((newLocationData) {
      print("listenning to location changes...........");
      print(newLocationData);
}

Of course I run location.enableBackgroundMode(enable: true); befor accessing the location and I added bellow permission to android manifist

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />

Any help appreciated.

Upvotes: 0

Views: 221

Answers (1)

Shashank Shrivastava
Shashank Shrivastava

Reputation: 26

In modern phones the background tasks are killed by the OS for battery optimization. I don't think there is a possible way to track location when the app is not in use. For a continuous task running n background there are certain other tings that needs to be done visit https://dontkillmyapp.com/ for such remedies

Upvotes: 0

Related Questions