Yukams / background_locator_fixed

A Flutter plugin for updating location in background.
MIT License
51 stars 104 forks source link

Location process closes after about 1 hour #87

Open nuno84 opened 1 year ago

nuno84 commented 1 year ago

Hi, I'm finding an issue and hope to get some suggestion on how to tackle it. So, I have a background location setup working fine in Android. Even when I close the app, it stays there monitoring as desired. However in my real phone: ZTE 7540N : Android 11 that "monitor icon" disapears from the phone topbar and monitoring ceases after about 1 hour. It works fine in the simulator, even with the same Android version, but for some reason that monitoring seems to crash only on the real phone. I also tried to use the release version on the simulator and it doesnt seem to fail after that time. Any idea of why it can be or where I can see some log/info or whatever that can help figuring out? It seems as if the phone automatically closes the monitor after a while... maybe to save energy? Maybe a hard-feature on Android? Maybe the phone closes the localization hardware and that causes the monitor to crash? Any idea is appreciated. Thank you so much.

mohammedX6 commented 1 year ago

You can change wakelock time in settings, the default is 60 minutes

nuno84 commented 1 year ago

Hi Mohammed, Thank you for your suggestion, I will try it. The only drawback to increase it to theoretical 'infinity' is battery consumption? Is there any other consideration that I should look for? Thank you Best regards

nuno84 commented 1 year ago

I changed it to 24*60, and it still gets deactivated after a while. It is usually a bit less than 1 hour so it may not be the issue? Any idea? Is there any way I can get some log output that could give some clue to follow? Thank you once again

nuno84 commented 1 year ago

This is what I have actually. Does anyone have an idea? I am sorry if I am being insistent but maybe this is an issue more people will have. Thank you for any idea, even if it is 'obvious' to you.

      await BackgroundLocator.registerLocationUpdate(
        LocationCallbackHandler.callback,
        initCallback: LocationCallbackHandler.initCallback,
        initDataCallback: data,
        disposeCallback: LocationCallbackHandler.disposeCallback,
        iosSettings: const IOSSettings(
            accuracy: LocationAccuracy.NAVIGATION,
            distanceFilter: 0,
            stopWithTerminate: true),
        autoStop: false,
        androidSettings: const AndroidSettings(
            wakeLockTime: 24*60,
            accuracy: LocationAccuracy.NAVIGATION,
            interval: 10,
            distanceFilter: 20,
            client: LocationClient.google,
            androidNotificationSettings: AndroidNotificationSettings(
                notificationChannelName: 'Location tracking',
                notificationTitle: 'Tacógrafo: monitor de localização',
                notificationMsg: 'Monitorização de localização em background',
                notificationBigMsg:'Ajuda a lembrar de potenciais alterações de estado do tacógrafo.',
                notificationIconColor: Colors.grey,
                notificationTapCallback: LocationCallbackHandler.notificationCallback)))
mohammedX6 commented 1 year ago

Hi, please try this library to disable battery optimizations for the app

https://pub.dev/packages/disable_battery_optimization/example

nuno84 commented 1 year ago

Hi again, I am really sorry but it still doesn't work. Do you have some more shot I can try? Is there any way to get the exit reason for these background processes somewhere on Android, like some log or similar? Thank you very much

mohammedX6 commented 1 year ago

Actually i am having the issue but it reduces when i disable battery optimizations , I don't know more about it sorry

nuno84 commented 1 year ago

Did you notice that the issue also happened to you after my question or you always had it (or maybe didnt need it before)? Thanks

mohammedX6 commented 1 year ago

It's happens before you asking

Abdulah-butt commented 1 year ago

Has anyone found a solution for this? i am facing same issue.

nuno84 commented 1 year ago

Has anyone found a solution for this? i am facing same issue.

No, I still would like to know.

Abdulah-butt commented 1 year ago

Ohh, I am also facing the same issue but for android>10...for android <=10 it is working fine

gamestap99 commented 1 year ago

try this link: https://dontkillmyapp.com/. I encountered this issue on Android 10 after following the link, and everything works fine.