Android get notification when a person enters or exits a region

821 views Asked by At

I am new to Android and developing a background service that would track whether the person is inside or outside of certain radius of an area (fixed lat/long coordinates).

Battery is critical and I don't need actual location (coarse location). It is fine if the event is delivered few minutes after the actual entry/exit as I need just one notification for entry and one for exit

I don't want alarm manager to trigger every 10 minutes to check current location as this would drain battery. Is there a way to achieve this with minimal battery drain and preferably without having the user to turn on GPS (consumes battery)?

2

There are 2 answers

2
Sergey Glotov On

It is called Geofencing. There is good article on Developers site. But it requires GPS (FINE_LOCATION).

Another solution: implement own Geofence-like "framework", but using network data (COARSE_LOCATION), not GPS. Yes, it requires periodical polling of location. A way to decrease battery drain is to poll less frequently. Also you can use location updates listener with a low priority.

0
Tony Vu On

Look like you can build a GeoFence and send notification on GeoFence transition. Please see this documentation: https://developer.android.com/training/location/geofencing.html