I develop a running app that use GPS location through LocationManager to deliver a Turn by Turn navigation experience.
Yesterday, ï discovered that I do not receive any location updates when app in background (phone locked) anymore.
This could not be a code regression because none of my previous git commit work neither. And I know I could receive location updates during last tests few weeks ago.
Then I tested other GPS-based app like Waze and others, but same result : none of them could update my position when going in background (except for GMaps), meaning I have no navigation instruction if my phone is locked. I have tested with other phones Samsung S8, S9, and Asus ... no changes.
Does anybody know if there was a recent changes in LocationManager behavior?
Thank you.
I found a good workaround.
In order to receive GPS location while in background with Android 8.0, we need to create a foreground service that ask for location update and pass it to your activity.
Here is an example of that.
Related
I have been trying consistent location tracking code in my application.
But it always fails in doze mode and some devices. Location tracking does not work smoothly in all types of android devices
Can anyone tell me a perfect solution or code to track user location irrespective of the state of device and it should work on all kind of android devices
What i have tried so far...
Job scheduler
Work manager
Forground service
Background service
Alarm manager
push Notification
But all of these fails at some point on some devices
None of them is perfect
They stop working in sleep mode or doze mode and sometimes they do not work at all
Can any one suggest a tested and a bug free solution?
I implemented getting location updates using FusedLocationProviderApi.
I need to track device location in background, when app is not running.
I followed the tutorials, I have a Service where I call requestLocationUpdates with an intent which starts a service.
I've purposely NOT implemented keeping a wake lock just to test and see that when the screen goes off, the device stops getting location updates. Once I verified that I could then go and implement the wake lock and expect the opposite, which is to see it working.
I used two devices: a Google Nexus 10 with KitKat and a Samsung Galaxy A5 (2016) with Lollipop.
On both devices, it keep sending updates (I'm sending the updates to a website).
I tested with screen off, after leaving device on a desk for a minute, and then walking again around the house.
I know Android 6 and Doze mode is more restrictive, but I want to nail and understand how it works on Android 4.4 and Android 5.
So frustrating! Any ideas how to actually make device go in sleep mode so I can see getting location updates stop working?
Funny, everything I've read is about making it work :)
EDIT: I'm confused why getting location updates is still working when screen is off even with an aggressive location update setup like the following:
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setFastestInterval(2);
locationRequest.setInterval(1000);
Thing about requesting location updates is that underneath it all, the LocationManagerService, which is what LocationManager uses, actually creates and acquires it's own wakelock. So technically, your device will never go to sleep as long as you have a location listener registered to actively receive GPS. Now, I know you are using Google's FusedLocationApi, but underneath it all, it does use LocationManager. If you are interested in understanding the location code a little better, here is the source code for LocationManagerService.
I have built an Android app with Geofences following the instructions from the developer training. I have tested my app several times during the production proccess with mock locations - it worked like a charm. However, when i tested my app with real location data (always with GPS enabled) the app showed a delay of 10-20 seconds after entering or leaving a geofence. My first thought was that the GPS signal might be inaccurate. But I later added Google Maps to my app and I can now see the accuracy of the GPS-signal according to the circle around my current location - all should be fine.
Has anybody faced a similar problemor know how to fix it?
Thanks
I'm using the navigator.geolocation objet to watch the position of the gps. I've found a bug, here are the steps:
1) Gps if off.
2) App start.
3) Gps is activated from the notification panel.
4) App doesn't notice any change.
At this point, only a window.location.reload() makes the app recognize that the gps is active.
If the App is started with the gps on, switching it on and off while the app is running cause no issue, the app recognize its state.
Do you know any way to solve this problem?
May be this will help you
https://github.com/mablack/cordova-diagnostic-plugin
I think the Geolocation API does not give you an error if the GPS is on/off, just a timeout error if it is not able to get a lock in the time limit you specify, but I tested it a while ago and I might be mistaking.
I am working with the Geofence API Sample application I've got it running and seems to work alright. I did make the modifications to it to use BroadcastReceiver instead of the IntentService.
But I will only get the notifications if I have some other app open that is using GPS such as Maps, or GPS Tester app.
If I don't have one of those apps open and I walk into the geofence zone nothing happens. But as soon as I launch one of them I will get the notification within a few seconds.
I ended up creating a service that forces the GPS to stay active by requesting location updates on a relatively quick interval.
While this is admittedly a poor work around for a "real" application. It worked for my purposes. In which I needed to be able to present a working proof of concept to an audience, which impeded my ability to use a geo points which were further spread out.
Even I too had a struggle with getting Geofence notification as soon I entered Geofence or Exit the one.There were always delays in notifications until I found a really nice Location Library called little-fluffy-location-library which serves my purpose.Location updates will be broadcast to your app periodically.
According the Documentation it says that:
The library works by using Froyo's passive location listener (only possible with Android 2.2 and up, hence why it works best with it), which listens to location updates requested by other apps on your phone. The most accurate location is broadcast to your app approximately every 15 minutes. If a location update hasn't been received from another app for an hour, the library forces a location update of its own.
I think you should give a try with this Library and Let me know if it works for you!!