Android Geofencing sample app only works if another app is open using GPS
Asked Answered
R

2

7

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.

Ragg answered 20/7, 2014 at 0:37 Comment(3)
Do you experience the same problem with the unmodified original app? Or is this tied to your change to using a BroadcastReceiver? And, if so, when you say "get the notification", how specifically are you testing that?Tb
@Tb Got the same result with the unmodified app (note that I had to add meta-data tag to the app manifest to get it to run at all. That was the only change from how I downloaded it though). I actually switched to the broadcast receiver because I was searching around to try to fix this problem and found a bunch of suggestions that a Receiver had helped people get the geofencing callbacks work more consistently. The sample code (and my receiver) send a notification to the notification bar when the geofence trigger fires. So my only test is whether or not I ever get that notification.Ragg
If you literally are walking into the geofence zone, try defining a larger zone and be in a moving vehicle. I'd be surprised if a registered geofence would trigger much GPS activity based on limited movement, and the network provider may be too inaccurate for a small geofence zone.Tb
R
3

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.

Ragg answered 20/7, 2014 at 13:58 Comment(0)
D
2

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!!

Dodecanese answered 25/7, 2014 at 13:17 Comment(1)
do you know if this library is still required with the current version of Android API? I'm having this same issue. GeoFence only triggers when another app such as Google Maps is using location services.Glycerin

© 2022 - 2024 — McMap. All rights reserved.