android - Multiple Point of Interest for Aproximity Location -
am trying implement proximity alert notification service in app , want have collection of poi (points of interest) when nearby of locations receive notification .i keep getting error
07-18 12:56:27.069: w/dalvikvm(12518): threadid=1: thread exiting uncaught exception (group=0x41ee1930) 07-18 12:56:27.079: e/androidruntime(12518): fatal exception: main 07-18 12:56:27.079: e/androidruntime(12518): java.lang.runtimeexception: error receiving broadcast intent { act=com.phlok.proximityalarm.broadcast flg=0x10 (has extras) } in com.phlok.multiplealert.proximityintentreceiver@42268478 07-18 12:56:27.079: e/androidruntime(12518): @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:768) 07-18 12:56:27.079: e/androidruntime(12518): @ android.os.handler.handlecallback(handler.java:725) 07-18 12:56:27.079: e/androidruntime(12518): @ android.os.handler.dispatchmessage(handler.java:92) 07-18 12:56:27.079: e/androidruntime(12518): @ android.os.looper.loop(looper.java:137) 07-18 12:56:27.079: e/androidruntime(12518): @ android.app.activitythread.main(activitythread.java:5231) 07-18 12:56:27.079: e/androidruntime(12518): @ java.lang.reflect.method.invokenative(native method) 07-18 12:56:27.079: e/androidruntime(12518): @ java.lang.reflect.method.invoke(method.java:511) 07-18 12:56:27.079: e/androidruntime(12518): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:795) 07-18 12:56:27.079: e/androidruntime(12518): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:562) 07-18 12:56:27.079: e/androidruntime(12518): @ de.robv.android.xposed.xposedbridge.main(xposedbridge.java:106) 07-18 12:56:27.079: e/androidruntime(12518): @ dalvik.system.nativestart.main(native method) 07-18 12:56:27.079: e/androidruntime(12518): caused by: java.lang.nullpointerexception 07-18 12:56:27.079: e/androidruntime(12518): @ com.phlok.multiplealert.proximityintentreceiver.onreceive(proximityintentreceiver.java:35) 07-18 12:56:27.079: e/androidruntime(12518): @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:758) 07-18 12:56:27.079: e/androidruntime(12518): ... 10 more
that's code here :
public class proximityalertservice extends service { private static final string tag = "proximityalertservice"; private static final long point_radius = 100; // in meters private static final long prox_alert_expiration = -1; // never expire private static final string prox_alert_intent = "com.phlok.proximityalarm.broadcast"; arraylist <latlonpair> positions; @override public int onstartcommand(intent intent, int flags, int startid) { toast.maketext(this,"start",toast.length_long).show(); createpositions(); registerintents(); log.d(tag,"adding..."); return super.onstartcommand(intent, flags, startid); } private void setproximityalert(double latitude, double longitude, final long eventid, int requestcode) { locationmanager locationmanager= (locationmanager) getsystemservice(context.location_service); bundle extras = new bundle(); extras.putlong("name", eventid); extras.putint("id", requestcode); intent intent = new intent(prox_alert_intent); intent.putextra(prox_alert_intent, extras); pendingintent proximityintent = pendingintent.getbroadcast(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++; log.d(tag,string.valueof(latitude)); intentfilter filter = new intentfilter(prox_alert_intent); registerreceiver(new proximityintentreceiver(), filter); } private void createpositions() { positions = new arraylist<latlonpair>(); positions.add(new latlonpair(53.4010626,-6.1804462)); positions.add(new latlonpair(53.4513078,-6.1537115)); positions.add(new latlonpair(53.4265686,-6.1715556)); log.d(tag,"locations added..."); } private void registerintents() { for(int = 0; < positions.size(); i++) { latlonpair latlon = positions.get(i); setproximityalert(latlon.getlatitude(),latlon.getlongitude(),i+1,i); log.d(tag,"intenets registered"); } }
that's broadcastreceiver code
public class proximityintentreceiver extends broadcastreceiver { // private static final int notification_id = 1000; @suppresswarnings("deprecation") @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); intent notificationintent = new intent(context, proximityalertservice.class); pendingintent pendingintent = pendingintent.getactivity(context, 0, notificationintent, 0); notification notification = createnotification(); notification.setlatesteventinfo(context, "phlok alert!", "omar,you near" + intent.getbundleextra("com.phlok.multiplealert.").get("name"), pendingintent); notificationmanager.notify( intent.getbundleextra("com.phlok.multiplealert.").getint("id"), notification); } private notification createnotification() { notification notification = new notification(); notification.icon = r.drawable.ic_launcher; 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.ledargb = color.white; notification.ledonms = 1500; notification.ledoffms = 1500; return notification; }
}
any appreciated
thank
check package name in onrecieve() method "com.phlok.multiplealert.")
Comments
Post a Comment