/ / Zrušené oznámenie sa znova doručuje, keď sa dotknete iného oznámenia. Android - java, android, notifikácie, androidové notifikácie, notificationmanager

Ak bolo upozornené na iné upozornenie, zrušené upozornenie bolo zrušené. Android - java, android, oznámenia, android-upozornenia, notificationmanager

Mám problém, keď bez ohľadu na to, akého upozornenia sa používateľ dotkne, dostávam stále rovnaké upozornenie, aj keď je zrušené.

Prvé upozornenie, ktorého sa užívateľ dotkne, je jedinéupozornenie, ktoré bude kedy doručené na môj očakávaný zámer, kým sa zariadenie nereštartuje (potom sa prvé dotykové upozornenie stane novým upozornením Hotel California). panel oznámení

Takto zostavujem upozornenia:

    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);

Potom mám toto vo svojom 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));

Bez ohľadu na to, ktorého upozornenia sa dotknem, v denníku Touched notification ID: 1234 sa vždy zobrazí, aj keď má upozornenie, ktorého sa dotknem, ID 56789.

Veľmi pochybujem, že ide o problém s mojím testovacím zariadením, ale v každom prípade to pomôže; Používam 2013 Nexus 7 s KitKat 4.4.4 s Dalvik runtime (nie ART) Build KTU84P.

odpovede:

2 pre odpoveď č. 1

Predajte svoje notificationId ako request code tu:

final PendingIntent pIntent = PendingIntent.getActivity(context, 0,
intent, 0, extras);

Zmeňte to na:

final PendingIntent pIntent = PendingIntent.getActivity(context, notificationId,
intent, 0, extras);

Pri porovnaní dvoch Intent inštancie, vrátane Bundles sa neporovnávajú. Z pohľadu systému Android sú teda dva zámery rovnaké.

Zaujímavé je, že reqCode (druhý argument v PendingIntent.getActivity(...)) je porovnané. A toto by malo vykresliť vaše Intents jedinečný.