我GCMBaseIntentService
在我的服务类中使用它扩展GCMBaseIntentService
了我覆盖的方法onMessage(Context,Intent)
。代码在这里:
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
//String message = getString(R.string.gcm_message);
String id=intent.getExtras().getString("event_id");
String message=intent.getExtras().getString("title");
String eventname=intent.getExtras().getString("event_name");
generateNotification(getApplicationContext(), id, message, eventname);
}
private static void generateNotification(Context context, String id, String message, String eventname)
{
int icon = R.drawable.ic_stat_gcm;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
//new intent
Intent notificationIntent = new Intent(context, EventDescription.class);
notificationIntent.putExtra("event_id", id);//need this id in the eventdescription activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, eventname, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
问题是,当我单击此通知并在Eventdescription
活动中并从意图中提取额外内容并打印 ID 时。它仅在第一次显示正确的值,之后对于每个通知,它始终显示第一个值。请帮忙!