У меня возникла проблема, когда независимо от того, к какому уведомлению прикасается пользователь, я всегда получаю одно и то же уведомление, даже если оно отменено.
Первое уведомление, к которому прикасается пользователь, — это единственное уведомление, которое когда-либо будет доставлено моему ожидающему намерению, до перезагрузки устройства (тогда первое уведомление, к которому прикоснулись, становится новым уведомлением Hotel California).
Вот как я строю уведомления:
final Bundle extras = new Bundle();
final int notificationId = Integer.parseInt(payload.getObjectId());
extras.putInt(NOTIFICATION_ID, notificationId);
final Intent intent = new Intent(context,
PushNotificationLauncherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtras(extras);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setContentText(payload.getText());
builder.setSmallIcon(R.drawable.icon_launcher);
builder.setAutoCancel(true);
final PendingIntent pIntent = PendingIntent.getActivity(context, 0,
intent, 0, extras);
builder.setContentIntent(pIntent);
final Notification notification;
if (Build.VERSION.SDK_INT < 16) {
notification = builder.getNotification();
} else {
notification = builder.build();
}
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notificationId, notification);
Тогда у меня есть это в моем PushNotificationLauncherActivity
:
final Bundle extras = getIntent().getExtras();
final int notificationId = extras
.getInt(SocialcastGoogleCloudMessageReceiver.NOTIFICATION_ID);
final NotificationManager notificationManager = (NotificationManager) this
.getSystemService(NOTIFICATION_SERVICE);
// please go away
notificationManager.cancel(notificationId);
Log.d(PushNotificationLauncherActivity.class.getSimpleName(),
"Touched notification ID: " + String.valueOf(notificationId));
Независимо от того, к какому уведомлению я прикоснусь, в журнале всегда будет отображаться Touched notification ID: 1234
, даже если уведомление, к которому я прикоснулся, имеет идентификатор 56789
.
Я очень сомневаюсь, что это проблема с моим тестовым устройством, но если это поможет; Я использую Nexus 7 2013 года с KitKat 4.4.4 со средой выполнения Dalvik (не ART) Build KTU84P.