Android location aware app - Set multiple points of interest without using multiple listeners
-
31-10-2019 - |
Question
I'm making an app which should show alerts whenever the user/device gets close to one of the predefined points of interest.
The only way I found for doing that (in fact i got it working like that) is to create a pending intent (with a unique name) for every single point of interest. But I think thats not the best way to do it in terms of resources..
Is it possible to achieve such functionality using just one pending intend instead of multiple separate ones?
Is there any other better way of doing that?
Thanks in advance
Mike
private void addProximityAlert(double latitude, double longitude, String poiName) {
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, 0, 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
);
IntentFilter filter = new IntentFilter(poiName);
registerReceiver(new ProximityIntentReceiver(), filter);
}
}
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow