notifications - Android how to send data to a broadcast receiver using intents -
i'm writing app in launch proximity alert every time i'm near specific point of interest(i read poi mysql db). when broadcastreceiver gets intent, creates notification , works fine. when click on notification activity start, need send parameters (basically strings) broadcast receiver, pass parameters activity want start. problem when try pass these parameters through intent broadcast receiver error: error receiving broadcast intent flg=0x10 has extras.
i sent parameters in way:
private void addproximityalert(annuncio a){ double latitudine = a.lat; double longitudine = a.lon; intent intent = new intent(prox_alert_intent); intent.putextra("nome", nome); pendingintent pi = pendingintent.getbroadcast(this, 0, intent,0); locationmanager.addproximityalert(latitudine, longitudine, raggio, alert_expiration, pi); intentfilter filter = new intentfilter(prox_alert_intent); registerreceiver(new proximityintentreceiver(),filter); }
this receiver:
public class proximityintentreceiver extends broadcastreceiver{ public void onreceive(context context, intent intent){ string nome = intent.getextras().getstring("nome"); log.v("nome", nome); } }
what missing?
06-29 22:42:46.103: e/androidruntime(3723): fatal exception: main 06-29 22:42:46.103: e/androidruntime(3723): java.lang.runtimeexception: error receiving broadcast intent { act=com.carmen.progettosmp.proximity_alert flg=0x10 (has extras) } in com.carmen.progettosmp.proximityintentreceiver@427a2f58 06-29 22:42:46.103: e/androidruntime(3723): @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:795) 06-29 22:42:46.103: e/androidruntime(3723): @ android.os.handler.handlecallback(handler.java:615) 06-29 22:42:46.103: e/androidruntime(3723): @ android.os.handler.dispatchmessage(handler.java:92) 06-29 22:42:46.103: e/androidruntime(3723): @ android.os.looper.loop(looper.java:153) 06-29 22:42:46.103: e/androidruntime(3723): @ android.app.activitythread.main(activitythread.java:4987) 06-29 22:42:46.103: e/androidruntime(3723): @ java.lang.reflect.method.invokenative(native method) 06-29 22:42:46.103: e/androidruntime(3723): @ java.lang.reflect.method.invoke(method.java:511) 06-29 22:42:46.103: e/androidruntime(3723): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:821) 06-29 22:42:46.103: e/androidruntime(3723): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:584) 06-29 22:42:46.103: e/androidruntime(3723): @ dalvik.system.nativestart.main(native method) 06-29 22:42:46.103: e/androidruntime(3723): caused by: java.lang.nullpointerexception: println needs message 06-29 22:42:46.103: e/androidruntime(3723): @ android.util.log.println_native(native method) 06-29 22:42:46.103: e/androidruntime(3723): @ android.util.log.v(log.java:117) 06-29 22:42:46.103: e/androidruntime(3723): @ com.carmen.progettosmp.proximityintentreceiver.onreceive(proximityintentreceiver.java:29) 06-29 22:42:46.103: e/androidruntime(3723): @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:785) 06-29 22:42:46.103: e/androidruntime(3723): ... 9 more
if creating notification, have create pendingintent in turn holds intent. can't set extras in intent?. also, sounds might benefit geofencing api. 1 more thing, looking string "ciao" key, shouldn't key nome?
Comments
Post a Comment