Weird issue with GPS in my Android app - android

There seems to be a problem with the communication between GPS and my android application.
About 1 in 10 times (after starting the application) the GPS isn't triggered by LocationManager.requestUpdates() (no GPS icon shows up etc.).
I've built in a timer that checks the GPS status every 15 seconds and when the GPS isn't working it'll remove the updates from the LocationManager and requests the updates again (the GPS status is checked through GpsStatus.Listener). Sometimes this wakes up the GPS and the problem is solved, but most of the time this doesn't work. However, turning off GPS on the device and turning it back on [sometimes] fixes this as well.
The application has lots of users with different devices who have this problem. I have a foreground service running at all times which requests these location updates in onStartCommand() and it removes the updates in onDestroy(). I've tried a lot of different solutions, but none of them seem to work (frustrating). I tried the fused location provider, but this doesn't always give the most accurate location/has no bearing/speed etc. Is there any other way to give the GPS a poke to wake it up or has anyone had this problem before? Also, I noticed that whenever this happens and I close the application, remove it from memory, and start it up again, the problem is fixed as well. It looks like something in the application is blocking it from communicating with the GPS (no idea if this is possible).
I'm curious if anyone has any suggestions as to what the problem could be.
Thanks in advance,

Wow, so I've been frustrated with this issue for a couple of weeks and apparently it's because of Flurry. Flurry reports GPS locations as well and this conflicts with the GPS of my app.. Calling FlurryAgent.setReportLocation(false) fixed this issue for me.

Related

Android Location GPS Track

I have a small test App that with an Android GPS API map fragment. I use FusedLocationProvider. TarketSDK=29. Using Java.
As long as the app is active it works beautifully. On locationUpdates, I add a new point to the track and everything looks great and stays accurate. The goal is to track my hike, total distance and track and show it on the map. Works great.
As soon I lock my phone or loses focus, then the updates stop and I no longer get location updates.
Solution seems to be:
Background Service (discouraged)
Foreground Service
PendingIntent
I have poured over the docs, StackOverflow, all examples/tutorials I can find, developer.android.com, etc. I have downloaded examples of the latter 2 from GitHub; they seem incredibly obtuse (probably just me).
What are the dis/advantages of ForegroundService vs PendingIntent?
How about a bare-bones example illustrating the min features of each to implement location updates while your phone is locked in your pocket or some other app is active? Just the template minimum.
I need to save the locationUpdates that occur while my app is not active or phone is locked; in order to fill in Track when activity is restored to the app.
Some simple end-to-end guidance from my working app to something that will maintain locationUpdates and save the data would be great.
Ok - I have answered my question in a roundabout way.
I had been Searching on "retrieving location updates when app is not active". This lead to the various solutions of background service, foreground service, pendingIntents, etc.
I eventually found that if you just start a Foreground Service with a Notification, even if your phone is locked or you switch active apps, your App continues to receive LocationUpdates; as the Foreground Service runs in the same thread and therefore activates your app code (if I understand the reasons why correctly).
So, I started searching on just how to start a Foreground Service. As anyone knows that has tried to figure this out lately, this has changed more than a couple times over recent versions. The online docs at developer.android.com are not up to date. You will spend a lot of time wondering why things do not work following these docs.
Eventually, with just searching on how to start a foreground service, I came across this simple and straightforward (non-youtube-video - don't you just hate those things) tutorial. https://androidwave.com/foreground-service-android-example/
I just added this code to my existing Mapping code that works when the app is active, and tested with locking the phone and putting it in my pocket and switching apps and doing the same. It appears to solve the problem.
Update: Added code to count number of location updates and average accuracy of each update holding the phone in hand, screen on and app active as the baseline. Phone locked, or App not active no difference in number of updates nor accuracy. Phone locked and in pocket, no difference in number of updates, but accuracy suffered by from an average of 10m to an average of 13m; to be expected I assume whilst in the pocket.

Android - GPS after a while no longer receives coordinates

I have a big problem with an Android application that I developed.
The purpose of the application (for business) is to track the position of the device continuously (24 hours on 24) detecting a GPS track on a regular interval, which will then be synchronized to the server to the unleashing of certain events.
Of course, over time the device in and out of buildings, acquiring and losing the GPS signal continuously.
Often the device is not used and remains in office for several hours inside the company headquarters without GPS signal. During the course of time the Android system continues to provide me constantly getLastKnowLocation
My problem is that after some time that the system is running, sometimes two or three days, sometimes more days, my app starts to receive from the system always the same coordinates, regardless of who is in the open or at closed. From what I understand the Android operating system no longer seems able to update his coordinates and It will always return the same getLastKnowLocation indefinitely.
My App therefore becomes useless.
You know how I can fix this?
Is there any process that Android can restart in order for the system to wake up. In My App I will acquire any permission, except for root permissions.
For now the only control that I put, and that if the system always gives me the same identity for a number of seconds I call the method requestLocationUpdates of the location manager again.
But I need something more robust, to give me a better guarantee of operation. I'd like to be sure as possible that the systems try really to get updated coordinates.
The only thing I can think of is that maybe I can ask the system to restart some process so that the Location Manager, is fully reset. Can I do this? What is the process to be killed?
Can you think of any other solution or you found yourselves in this issue?
Thank you.

GPS stops retrieving recent updates

I'm having a problem with a few users that their gps tracking app stops updating their position, and keeps sending old position to our backend.
The implementation was based on FusedLocation tutorials, and it works. It is just that, with a few people, it suddenly stops working.
Not sure if it's related, but what happens if I try to get a position while the last try is still trying to get (with the gps icon still blinking)?
The only hint I know is that when I disconnect and connect again to the GoogleApiClient, the gps works fine again. Does anyone also know anything that might be causing it?
I'm using Play Services: 7.5.0
Edit: The interval between each gps request is 30 seconds.

How to check if your location has been confirmed in Android?

I'm building an app that involves getting the user's current location. I already have it getting the location, but sometimes it's inaccurate.
I've noticed that when I start the app, a location services symbol appears greyed out in the notice bar. While it's greyed out my app will sometimes report that I'm where I was an hour ago, even if I'm miles away. A few moments later the symbol will be solid and then the app reports the correct location.
The phone seems to understand that it's not entirely sure for moment. Is there a way to check this programmatically?
I'm aware of how to check if location services are enabled. The problem is that my location is not updating quickly enough and I'd like to wait until the phone is absolutely sure of where I am.
My current fix is to make a fake loading screen that just forces the user to sit for a few seconds, but this seems a bit sloppy. Also, I have no guarantee that the location will have updated properly by the end of the three seconds.
I'm trying to avoid making the app run in the background and check periodically because I'm worried about draining the battery.

Why is locationmanager returning old location fixes with new gettime-timestamp?

We have an app that upon user action tries to get a location fix. It listens both on GPS and network and has a time/accuracy based decision matrix to determine when to stop listening and what fix to return.
We have noticed, on occasion, a very strange behaviour. We use the classic way to see how old the fix is, like so:
long age = now - newLocation.getTime();
if(age >= prefs.getLocationMaxAge()){
Log.d(TAG, "location too old.");
return;
}
But sometimes, the location.getTime returned from the OS has an age of perhaps 15-20 seconds, according to the returned timestamp, although we can tell for certain that it's very old. For example, if the longitude/latitude fix is from a position that the handset was on 30 minutes ago!
It seems to happen both from Wi-Fi and network, but not GPS. To me, this is totally crazy. Has anyone else seen this and is there any way around it?
We have gotten it on a couple of different phones, most recent one is Samsung Galaxy S II.
Help would be extremely welcome.
EDIT: To be really clear, the problem is that the "onlocationchanged" callback gets called by the OS with a location with a timestamp age of perhaps a couple of seconds, when I know for certain that the longitude/latitude in the "new" fix is a place where the phone hasn't been at for at least 30 minutes.
This makes it kind of hard to accurately determine where the handset it...
It seems to happen both from Wi-Fi and network, but not GPS
This seems fair, because in the Wi-Fi and network cell-site based triangulation, the accuracy is very bad. They are probably using cached locations which date back to 30 minutes ago. Unless you have not changed your cell-site or moved to another building so that new APs can be discovered, I'm afraid you will get only cached locations. If you want fresh locations use the GPS provider.

Categories

Resources