I am trying to create some proximity alerts, but I cannot get them to work ...
I think the broadcast receiver is overwritten and thus only processes the latest broadcast. So if I had two points that were close only to those whose intention was created last, a warning is generated ...
I read that I have to use request codes, but I have no idea how to do this ...
My method of setting pending intent and broadcast receiver ...
private void addProximityAlert(double latitude, double longitude, String poiName, String intentfilter) { Bundle extras = new Bundle(); extras.putString("name", poiName); Intent intent = new Intent(PROX_ALERT_INTENT+poiName); intent.putExtras(extras); PendingIntent proximityIntent = PendingIntent.getBroadcast(MainMenu.this, requestCode, intent, 0); locationManager.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 proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected ); requestCode++; IntentFilter filter = new IntentFilter(intentfilter); registerReceiver(new ProximityIntentReceiver(), filter); }
My Broadcast Class
public class ProximityIntentReceiver extends BroadcastReceiver { private static final int NOTIFICATION_ID = 1000; @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 { Log.d(getClass().getSimpleName(), "exiting"); } NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, null, 0); Notification notification = createNotification(); notification.setLatestEventInfo(context, "Proximity Alert!", "You are approaching: " +intent.getExtras().get("name"), pendingIntent);
Could you help me??? I'm really stuck on this ...
Any help would be really appreciated!
android geolocation android-pendingintent broadcast proximity
mixkat
source share