我收到帶有數據(意向)的推送通知。如果我收到兩個或更多使用不同ID的通知,但打開一個活動和ID相同。例如,我收到三個不同id = 1,2,3的通知。但是當Activity開始時,使用一個id = 3.當我用ids 1和2單擊第一或第二個通知時,打開id爲3的Activity。可以幫助理解我在代碼中的錯誤嗎?推送通知打開具有相同意圖的活動
NOTIFICATION_ID ++;
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(msg.getString("title"))
.setContentText(msg.getString("message"))
.setDefaults(Notification.DEFAULT_SOUND)
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(Picasso.with(getApplicationContext()).load(msg.getString("icon")).get()).setSummaryText(msg.getString("message")))
.setAutoCancel(true);
Log.e("msg---",msg.toString());
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(this, ActivityDetail.class));
// intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(Keys._PostId,msg.getString("id"));
intent.putExtra(Keys._Image, msg.getString("icon"));
intent.putExtra(Keys._PostType, msg.getString("post_type"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
你需要設置'PendingIntent'按你的IDS。 –
請嘗試這可能會幫助你'PendingIntent contentIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);'謝謝;-) –