I am not sure if this is a bug with the new Android GeoFence sample code or my understanding of what it is supposed to do is wrong. The sample app creates geofences but does not alert when geofence is breached. If anyone would like to give this a try and confirm, you can download the sample code from here :
https://developer.android.com/training/location/geofencing.html
This is what I was expecting the sample app to do :
In this case, no notifications nor any log messages were registered which means that "ReceiveTransitionsIntentService" never got called. One observation is that when I drive to the first location and then add a new geofence right at that location, the notification gets fired immediately, but any other location (geofence) I set and drive to, nothing happens.
Any idea why? Is my understanding correct about the sample app's functionality?
Do I need to do anything in addition to what is in the sample code to receive an alert when I breach the geofence while driving? Is geofence monitoring separate from creating geofences, what am I missing here?
Highly appreciate any input, We are very eager to use this in our app but right now we are stuck.
Thanks, Torri.
Geofencing combines awareness of the user's current location with awareness of the user's proximity to locations that may be of interest. To mark a location of interest, you specify its latitude and longitude. To adjust the proximity for the location, you add a radius.
Essentially, the error is telling that you're dealing with a misbehaving app or app service that isn't collaborating well with GeoFencing.
The geofencing API allows you to define perimeters, also referred to as geofences, which surround the areas of interest. Your app gets a notification when the device crosses a geofence, which allows you to provide a useful experience when users are in the vicinity.
First of all, your understanding of the app's functionality is correct. Whenever you enter/leave one of your geofences it shows you that in a notification (it's always updating the same notification btw, so keep an eye out for it or you might miss one of the events).
Second, be careful because Geofence 1, by default, is only triggering ENTER events. So if you leave that geofence area after being inside it you won't get a notification for that! You can change this behavior in the creation of the mUIGeofence1 object on MainActivity.java.
Lastly, as with all things related to location, this API isn't perfect.. From my tests so far I have never seen it start up the GPS, so when outside it pretty much seems to rely on network locations which can easily not fall under a 500m radius geofence even if you're standing right in the middle of it. During one of the presentations at IO, Reto Meier mentioned that the API would be clever enough to handle battery drain the best way possible, so it would only turn on GPS when the user starts getting close to a geofence - which makes sense - but this never seems to happen unfortunately.
The API will never "turn on" GPS. You have to start GPS yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With