android - Can a broadcastReceiver catch multiple broadcasts? -
i trying create multiple proximity alerts cant work...
i think broadcast receiver gets overwritten , handling last broadcast. if had 2 points close 1 intent created last generate alert...
i read should use request codes have no idea on how that...
my method setting pending intents , 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, // latitude of central point of alert region longitude, // longitude of central point of alert region point_radius, // radius of central point of alert region, in meters prox_alert_expiration, // time proximity alert, in milliseconds, or -1 indicate no expiration proximityintent // used generate intent fire when entry or exit alert region detected ); requestcode++; intentfilter filter = new intentfilter(intentfilter); registerreceiver(new proximityintentreceiver(), filter); }
my broadcastreceiver 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 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; } }
can please me??? i'm stuck this...
any appreciated!!!
i got working after all...
exactly looking for: http://www.gauntface.co.uk/blog/2010/01/04/proximity-alerts-in-android/
modifications made
private void addproximityalert(double latitude, double longitude, string poiname) { bundle extras = new bundle(); extras.putstring("name", poiname); extras.putint("id", requestcode); intent intent = new intent(prox_alert_intent); intent.putextra(prox_alert_intent, extras); pendingintent proximityintent = pendingintent.getbroadcast(mainmenu.this, requestcode , intent, pendingintent.flag_cancel_current); locationmanager.addproximityalert( latitude, // latitude of central point of alert region longitude, // longitude of central point of alert region point_radius, // radius of central point of alert region, in meters prox_alert_expiration, // time proximity alert, in milliseconds, or -1 indicate no expiration proximityintent // used generate intent fire when entry or exit alert region detected ); requestcode++; } private void initialisereceiver() { intentfilter filter = new intentfilter(prox_alert_intent); registerreceiver(new proximityintentreceiver(), filter); }
package michaels.pack; import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.graphics.color; import android.location.locationmanager; import android.util.log; 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 receiverrrrrrrrrrrrrrrrrr"); } 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 approaching: " +intent.getbundleextra("michaels.pack.proximityalert.").get("name"), pendingintent); //here------------------------------------- notificationmanager.notify( intent.getbundleextra("michaels.pack.proximityalert.").getint("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.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; } }
Comments
Post a Comment