我正在使用GCMBaseIntentService。 在我的serive类中扩展了GCMBaseIntentService,我重写了onMessage(Context,Intent)方法。 代码如下: protected void onMessage(Context context,Intent intent)Log.i(TAG,“Received message”);从通知中打开活动-Android
//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。它仅在第一次显示正确的值,然后对于每个通知它始终显示第一个值。请帮忙!
好thnx ..我会尝试! – gaurav414u
它不工作,仍然发生同样的事情! – gaurav414u
您能够获取多个通知,或者您一次只检查一个通知。还有你检查是否String id = intent.getExtras()。getString(“event_id”);你传递给generateNotification的值是不同的? – curious