Comments (3)
I think I can point at the various things I've done to keep the app alive, but note that it's not always successful, some manufacturer's implementations are quite aggressive and still manage to kill it. Also in some cases I'm not able to achieve the 'kinda guaranteed' 5 minutes interval in doze mode, despite following the Android guidance.
So main thing is to create a service with a notification, that's the important bit.
https://github.com/mendhak/gpslogger/blob/master/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java#L90-L97
In the onstartcommand of the service, I'm also returning a sticky variable:
https://github.com/mendhak/gpslogger/blob/master/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java#L144 - it's from so long ago I can't remember what this is doing, I think it tells the OS to restart the service in case it's killed.
There's more, in the onDestroy, where the OS might destroy the app while it's running, I've sent a broadcast to the app itself to restart.
https://github.com/mendhak/gpslogger/blob/master/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java#L155-L158
You can see as well, on low memory, an attempt to log the next point after a few minutes have passed, to give the OS some time to rest. https://github.com/mendhak/gpslogger/blob/master/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java#L163-L170
When I set the alarm for the next point I'm using the AlarmManager. Not sure if it's the best approach and I think JobManager is recommended now but I haven't had time to look into it. Anyway the AlarmManager: https://github.com/mendhak/gpslogger/blob/master/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java#L1012
I think that's it, aside from that some attempts at not being too aggressive with battery usage. eg, adding a bit of sleep in the loops. Not trying to use too much memory. No science behind these last bits, it's more superstition than anything else.
from gpslogger.
I think you'll have trouble keeping a websocket connection open 'forever'. The service needs to be resilient against pauses and restarts and doze mode, and all their documentation indicates that they want your service to be doze compliant. That is, it gets stopped when the user has turned the phone off, it is allowed to wake up every 5 minutes (or 20) and do some network work, and then go back to sleep. A websocket of course is holding the connection open so you may run into issues.
The most common way I've seen around this is to use Firebase Cloud Messaging, which works even in doze mode.
from gpslogger.
Thanks you for your time.
I had my Foreground Notification and it last from 4 to 30 hours depending on the mobile device.
I realised that it is a lost battle to fight against the fact that the service will be killed at some point. I was at this point when I opened this issue.
I cannot use Firebase for my case.
Now, I think that I found the most close way to achieve my goal. Like you said, I use AlarmManager to execute periodically and checks if Foreground Service is still alive. If not, it relaunch it again. For Android +10 (API +29), in order to be allowed to start from background, SYSTEM_ALERT_WINDOW permission is needed to be declared in Android Manifest file and to be requested and granted.
I use an one second periodic interval, but AlarmManager is fired in average every 60 seconds on my mobile device.
I hope this thread helps someone and if anyone has a finest solution it is welcome
from gpslogger.
Related Issues (20)
- [Feature Request] - Movement detection HOT 3
- GPSLogger does not start on old android phone (android version 5.1.1)
- App doesn't respect statusbar / camera cut out space HOT 2
- "Package installer keeps stopping": can't install on new Pixel 8 HOT 11
- [Feature request] Add activity type setting
- [Feature request] Send to multiple custom urls HOT 1
- [Feature request] GPS polling and file logging with different peroids HOT 2
- [Feature request] Add BLE Uart as destination for output HOT 2
- Upload all files that have failed to upload when network becomes available HOT 2
- why Intent serviceIntent = new Intent(AppSettings.getInstance(), GpsLoggingService.class); HOT 1
- [Feature request] Auto logging while driving HOT 3
- Email auto sending does not work as set HOT 15
- Start logging after button tab without confirmation HOT 1
- On Android 12 GPS logger messes up with Trimble Mobile Manager HOT 1
- [Feature Request] Have you a plan to add Kalman filter HOT 2
- wrong recording interval (1minute instead of 1second) HOT 2
- Inconsistent Speed Data in GPSLogger App v130 HOT 1
- GPSLogger doesn't notify the user when it can't write to files, leading to data loss HOT 8
- Custom URL logger to OwnTracks with speed in km/h HOT 6
- GPSLogger vs GPS Logger HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpslogger.