private static void addProximityAlert(double latitude, double longitude) { if (_lastProximityIntent != null) locManager.removeProximityAlert(_lastProximityIntent); Intent intent = new Intent(PROX_ALERT_INTENT); _lastProximityIntent = PendingIntent.getBroadcast(listener.getContext(), 0, intent, 0); locManager.addProximityAlert( latitude, // the latitude of the central point of the alert region longitude, // the longitude of the central point of the alert region POINT_RADIUS, // the radius of the central point of the alert region, in meters PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate // no expiration _lastProximityIntent // will be used to generate an Intent to fire when entry to or exit // from the alert region is detected ); IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT); listener.getContext().registerReceiver(new ProximityIntentReceiver(), filter); }
@Override public void onReceive(Context context, Intent intent) { String key = LocationManager.KEY_PROXIMITY_ENTERING; Boolean entering = intent.getBooleanExtra(key, false); if (entering) { Log.d(getClass().getSimpleName(), "entering"); } else { listener.Alert(); Log.d(getClass().getSimpleName(), "exiting"); } }