Open miistakis opened 2 years ago
Make sure you use startFouregrond and no battery optimization is applied to the app. If you are not using androidx I would use the mauron85 one.
I was using mauron85, but was running into some permission issues, which were fixed when I switched to this one, but its not working in the background.
I assume these are the ones you mean: startForeground: true, saveBatteryOnBackground: false,
Thanks
Also battery optimization in the app settings in the OS. But you'll need to debug using android studio probably...
Ok, will check out the power settings in the OS, hadnt thought of that. I have been using android studio, no real stand out issues.
Is start and end task required, or just for long IOS tasks?
Here is what happens in the log when it goes into background:
D/CordovaActivity: Paused the activity. I/com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin: App will be paused multitasking=true I/chromium: [INFO:CONSOLE(195)] "[INFO] App is in background", source: file:///android_asset/www/js/app.js (195) D/com.marianhello.bgloc.service.LocationServiceImpl: Service in [STARTED] state. cmdId: [3]. startId: [2] D/CordovaActivity: Stopped the activity. I/com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin: App is no longer visible V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@b5e70b3, this = DecorView@713fe96[MainActivity]
@HarelM is there a power setting specific to android? The setting I see in the documentation is for IOS, which I have set as well, but wondering if there is something else specific for android?
I have the app working in background, but it needs to be connected via USB, which makes me think of your power recommendations. The OS settings are to not optimize for battery and to allow battery usage in background, but still soon as I disconnect from power it no longer records points in background.
No, just the OS battery optimizing...
@HarelM Are there different settings for background vs sleep? If I just put the app in the background of the phone, say work on a different app, it still works fine, even disconnected from the usb cable. But if I let the device go dark, if it is not plugged into USB power, it stops working, until you plug it in or open the device back up.
I'm not aware of different settings. I would also consider comparing you other apps and see if the behavior is similar or different.
@miistakis , have you found something to fix this issue ? I have the same issue. In foreground, I got the entire ride, in background, it stops and resend location when app is resumed. On my logs, I have nothing but the last position returned by the plugin while in background mode, and the first returned when app in foreground again.
For information, I have disabled the battery optimization from OS and still not working. I have tried with @capacitor-community/background-geolocation and I got the entire ride in foreground and background, if this can help to investigate @HarelM
@mrshlle I have a user base of 50k users that uses this plugin and it works as expected.
Moreover, I tried to switch to @capacitor-community/background-geolocation and found it not to work in specific cases.
Make sure you use startForeground
in order to get the activity the right priority so it won't get lost.
I also don't listen to event when in background but rather get the last locations from the sqlite db and remove them.
You can see my code here:
https://github.com/IsraelHikingMap/Site/blob/6a721853c4c8b7e7e0f8d24514a6c3b02a61f069/IsraelHiking.Web/src/application/services/geo-location.service.ts
I can assure you the code above is production ready and battle tested.
@mrshlle No, I found the issue was device specific, or maybe that make model (Umidigi A9), and worked on every other device I tested on, so I just released it as is, and have yet to have a complaint.
@HarelM yep, startForeground
is set to true.
I have tried with your code, and by taking the last location from sqlite, but the problem comes from the locations that are not even stored when in background.
But thanks for your support, I will try more to make it work for my needs.
@miistakis I see, I will test on other devices then, hoping mine is not used a lot.
Thanks for your replies
I think the issue may be related to https://github.com/mauron85/cordova-plugin-background-geolocation/issues/688 and permissions on new android devices, could that fix be implemented as using this repo does not allow always on some of our devices.
If you think possible I'll give it a go.
I don't have issues in my App, so I can't relate to this issue. If you would like to debug it and open a PR go ahead.
@HarelM The Sync API is not receiving list of Locations. I have updated the url and syncurl in parameters. Under demo app -> on start it does give me the location only one time but nothing returning when app is on background/foreground and no data returning back to the sync api. below are my parameters settings ![Uploading image.png…]()
Hi @HarelM, I am trying to use this plugin again because being able to track location when app is killed is really usefull.
For the moment, I use @capacitor-community/background-geolocation plugin. When I started implementing it, I had a problem that stopped location after a while in background, and the way to resolve it, was this answer.
I know you are not facing this issue, so I just would like to know if you can help me finding the approximate same method, that is called when it's time to pause the plugin. (In the other plugin, you can find it on this file, line 329) I have found an "onPause" method on "BackgroundGeolocationPlugin" but not sure if it's where I can do something.
Sorry, I can't help unfortunately. I tried migrating to the community plugin and it wasn't good enough for that reason mainly. If your happen to find why and fix it I'll be happy to use the capacitor community one instead of this, as this one is just too complicated... Here's the relevant issue: https://github.com/capacitor-community/background-geolocation/issues/80
@HarelM Are there different settings for background vs sleep? If I just put the app in the background of the phone, say work on a different app, it still works fine, even disconnected from the usb cable. But if I let the device go dark, if it is not plugged into USB power, it stops working, until you plug it in or open the device back up.
Some Manufacturers have very aggressive battery saving apps, that tend to disable any background app they dont know about. So first of all it is better to check battery saver app (instruction on how to do this depends on manufacturer of the phone).
I think the issue may be related to mauron85#688 and permissions on new android devices, could that fix be implemented as using this repo does not allow always on some of our devices.
If you think possible I'll give it a go.
This can be fixed by just adding cordova-plugin-diagnostics plugin to request permissions and by adding required permissions to your config file
My solution is to push a high-priority Firebase message and location permission is always allowed.
This is on an Andriod os 10, using the 1.1 plugin as the app isnt andriodx enabled.
Everything works great in foreground, but soon as it goes into background it suspends activity, until I bring it back to foreground. Any suggestions on what to try would be appreciated.