android - Error receiving broadcast Intent when passing multiple points -
i have read every post on regarding , tried solutions felt relative, still not know why happening. here logcat:
02-20 18:10:27.959: d/proximityintentreceiver(17636): entering receiver 02-20 18:10:27.959: w/dalvikvm(17636): threadid=1: thread exiting uncaught exception (group=0x40adf9f0) 02-20 18:10:27.959: e/androidruntime(17636): fatal exception: main 02-20 18:10:27.959: e/androidruntime(17636): java.lang.runtimeexception: error receiving broadcast intent { act=com.javacodegeeks.android.lbs.proximityalert flg=0x10 (has extras) } in com.example.newmaps.proximityintentreceiver@41550140 02-20 18:10:27.959: e/androidruntime(17636): @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:737) 02-20 18:10:27.959: e/androidruntime(17636): @ android.os.handler.handlecallback(handler.java:605) 02-20 18:10:27.959: e/androidruntime(17636): @ android.os.handler.dispatchmessage(handler.java:92) 02-20 18:10:27.959: e/androidruntime(17636): @ android.os.looper.loop(looper.java:137) 02-20 18:10:27.959: e/androidruntime(17636): @ android.app.activitythread.main(activitythread.java:4424) 02-20 18:10:27.959: e/androidruntime(17636): @ java.lang.reflect.method.invokenative(native method) 02-20 18:10:27.959: e/androidruntime(17636): @ java.lang.reflect.method.invoke(method.java:511) 02-20 18:10:27.959: e/androidruntime(17636): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:817) 02-20 18:10:27.959: e/androidruntime(17636): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:584) 02-20 18:10:27.959: e/androidruntime(17636): @ dalvik.system.nativestart.main(native method) 02-20 18:10:27.959: e/androidruntime(17636): caused by: java.lang.nullpointerexception 02-20 18:10:27.959: e/androidruntime(17636): @ android.app.pendingintent.getactivity(pendingintent.java:195) 02-20 18:10:27.959: e/androidruntime(17636): @ com.example.newmaps.proximityintentreceiver.onreceive(proximityintentreceiver.java:36) 02-20 18:10:27.959: e/androidruntime(17636): @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:728) 02-20 18:10:27.959: e/androidruntime(17636): ... 9 more
here code within map class create proximity alert along location listener:
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(map.this, requestcode , intent, pendingintent.flag_cancel_current); lm.addproximityalert( latitude, // latitude of central point of alert part longitude, // longitude of central point of alert part 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 part detected ); requestcode++; intentfilter filter = new intentfilter(prox_alert_intent); registerreceiver(new proximityintentreceiver(), filter); toast.maketext(getapplicationcontext(),"alert added"+requestcode,toast.length_short).show(); } public class mylocationlistener implements locationlistener { public void onlocationchanged(location location) { toast.maketext(map.this, "distance point:", toast.length_long).show(); } public void onstatuschanged(string s, int i, bundle b) { } public void onproviderdisabled(string s) { } public void onproviderenabled(string s) { } }
here proximity 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 receiver"); } 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("deucalion0.proximityalert.").get("name"), pendingintent); //here------------------------------------- notificationmanager.notify( intent.getbundleextra("deucalion0.proximityalert.").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.defaults |= notification.default_sound; notification.ledargb = color.white; notification.ledonms = 300; notification.ledoffms = 1500; homecoming notification; }}
when run application , open map fine, crashes while phone sits there, have no thought doing, maybe location listener? appreciate help prepare clueless @ point.
from logcat:
caused by: java.lang.nullpointerexception @ android.app.pendingintent.getactivity(pendingintent.java:195) @ com.example.newmaps.proximityintentreceiver.onreceive(proximityintentreceiver.java:36)
the problem appears line when phone call getactivity()
:
pendingintent pendingintent = pendingintent.getactivity(context, 0, null, 0);
which confusing. purpose of pendingintent start component, in case activity, passing null
intent. want line of code do?
android android-intent android-broadcast
No comments:
Post a Comment