Estoy tratando de crear múltiples alertas de proximidad pero no puedo hacer que funcione ...¿Puede un broadcastReceiver captar múltiples transmisiones?
Creo que el receptor de difusión se sobrescribe y, por lo tanto, solo está manejando la última transmisión. Así que si tuviera dos puntos cercanos sólo aquel cuya intención fue creado el pasado generará una alerta ...
leí que debo utilizar códigos de petición pero no tengo ni idea de cómo hacer eso ...
Mi método para establecer las intenciones pendientes y el receptor de radiodifusión ...
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);
}
Mi clase BroadcastReceiver
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);
//here-------------------------------------
notificationManager.notify(NOTIFICATION_ID, notification);
}
private Notification createNotification() {
Notification notification = new Notification();
notification.icon = R.drawable.androidmarker;
notification.when = System.currentTimeMillis();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.flags |= Notification.FLAG_INSISTENT;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.ledARGB = Color.WHITE;
notification.ledOnMS = 300;
notification.ledOffMS = 1500;
return notification;
}
}
¿Puedes ayudarme por favor? Estoy realmente atascado con esto ...
Cualquier ayuda sería muy apreciada !!!
Sólo para hacerle todos saben que publiqué una actualización en mi código original que incluye un ejemplo completo en GitHub: http: //www.gauntface.co.uk/pages/blog/2010/12/28/how-to-multiple-proximity-alerts-in-android/ –
¿Cómo se elimina su alertas? El mío solo sigue creciendo. :( – deucalion0
Hace tiempo que no recuerdo lo que hice. – mixkat