我正在使用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