我正在展示一个与我的项目相关的库中的通知,当点击通知时,通知会跳转到一个Activity(ReceivingActivity)。点击通知后,Activity会打开,但是附加在其中的extras没有被接收到。
通知触发代码 - 当我收到gcm消息时,我调用sendNotification
,而通知代码位于库中。
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
private void sendNotification(Bundle extras) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent redirectIntent = new Intent(this, Class.forName("com.xyz.kljdf.ReceivingActivity"));
redirectIntent.putExtra("key", "value"); // These extras are not received in ReceivingActivity onCreate(), see the code below
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
redirectIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(((Context)this).getResources().getIdentifier("icon", "drawable", getPackageName()))
.setContentTitle(extras.getString(PushConstants.TITLE))
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(extras.getString(PushConstants.ALERT)))
.setContentText(extras.getString(PushConstants.ALERT));
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
检查ReceivingActivity中的额外内容...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_receiving);
Log.i("extras..... @@@@@@", getIntent().getExtras().toString()); //NPE here
}
我需要帮助弄清如何传递额外参数并正确接收它们。