Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase consistency of Android geofence enter/exit notifications?

Tags:

I am using the built in geofence APIs (play services) and have been having mixed results. It looks like after setting a geofence, the notifications for entering/exiting are very inconsistent even when GPS is on, with an up-to-date location (LocationClient connected, running in the background.) I started monitoring (polling) location changes and distances in a debug text field, and saw that, even when based on the location registered by the device and the location of the geofence I am technically inside/outside of the geofence, notifications are sometimes triggered and sometimes not. Any way to make this more predictable? I am almost tempted to abandon this api and implement my own (battery draining) geofences based on polling of device location.

like image 259
oviroa Avatar asked Jan 28 '14 18:01

oviroa


People also ask

What is the recommended radius for geofence?

For best results, the minimum radius of the geofence should be set between 100 - 150 meters.

What is the recommended radius for a geofence Huawei?

What is the recommended radius for a geofence? It is recommended that the geofence radius be at least 200 meters.

What is geofencing API?

Geofence API gives a device the power of monitoring the circular area in the world. Photo by KOBU Agency on Unsplash. Google Geofence API is used when you want to notify users if they are near the specific area in the world (such as Shopping Malls, Airport, Restaurants etc.).


1 Answers

A couple of suggestions:

  1. Make sure you're using a BroadcastReceiver and not a Service to receive the transitions, otherwise you will not/might not get it if your app gets killed/turned off. As discussed here: Android Geofence eventually stop getting transition intents

  2. Make sure you recreate your geofences after the device is rebooted, preferably using a boot-broadcast receiver. As discussed here: Do Geofences remain active in android after a device reboot

  3. One other common misconception, and which stumped me since it's different than IOS is that you'll always get a trigger immediately for a newly created geofence, if the device discovers that you're inside the geofence when creating it. I have solved this myself using a "grace period" for newly created geofences, which i explained in this thread: addProximityAlert doesn't work as expected

Finally one important thing: Having your LocationClient connected in your app or not should not matter at all if you follow the points above. My process for adding or removing Geofences in my code is basically:

  1. Create and connect locationclient.

  2. In connect-callback, do adding/removing of geofence(s)

  3. In geofence-result callback, disconnect locationclient.

Every time this happens, my location client is only connected a few seconds in total. The operating system will still produce geofence alerts and call my BroadcastReceiver whenever they happen.

If you do these things I bet your experience will improve.

Hope this helps!

like image 80
Mathias Avatar answered Sep 21 '22 06:09

Mathias