我正在编写一个应用程序,每当我靠近特定的兴趣点时,我都会在其中启动接近警报(我从 mysql db 读取 poi)。当 BroadcastReceiver 获得意图时,它会创建一个通知并且一切正常。当我单击通知时,我希望启动一个活动,因此我需要向广播接收器发送一些参数(基本上是字符串),以便它可以将此参数传递给我要启动的活动。问题是,当我尝试通过意图将这些参数传递给广播接收器时,我收到此错误:错误接收广播意图 flg=0x10 有额外内容。
我以这种方式发送参数:
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);
}
这是接收器:
public class ProximityIntentReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent){
String nome = intent.getExtras().getString("nome");
Log.v("nome", nome);
}
}
我错过了什么?
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): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:795)
06-29 22:42:46.103: E/AndroidRuntime(3723): at android.os.Handler.handleCallback(Handler.java:615)
06-29 22:42:46.103: E/AndroidRuntime(3723): at android.os.Handler.dispatchMessage(Handler.java:92)
06-29 22:42:46.103: E/AndroidRuntime(3723): at android.os.Looper.loop(Looper.java:153)
06-29 22:42:46.103: E/AndroidRuntime(3723): at android.app.ActivityThread.main(ActivityThread.java:4987)
06-29 22:42:46.103: E/AndroidRuntime(3723): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 22:42:46.103: E/AndroidRuntime(3723): at java.lang.reflect.Method.invoke(Method.java:511)
06-29 22:42:46.103: E/AndroidRuntime(3723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
06-29 22:42:46.103: E/AndroidRuntime(3723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-29 22:42:46.103: E/AndroidRuntime(3723): at dalvik.system.NativeStart.main(Native Method)
06-29 22:42:46.103: E/AndroidRuntime(3723): Caused by: java.lang.NullPointerException: println needs a message
06-29 22:42:46.103: E/AndroidRuntime(3723): at android.util.Log.println_native(Native Method)
06-29 22:42:46.103: E/AndroidRuntime(3723): at android.util.Log.v(Log.java:117)
06-29 22:42:46.103: E/AndroidRuntime(3723): at com.carmen.progettosmp.ProximityIntentReceiver.onReceive(ProximityIntentReceiver.java:29)
06-29 22:42:46.103: E/AndroidRuntime(3723): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:785)
06-29 22:42:46.103: E/AndroidRuntime(3723): ... 9 more