0
我正在使用推送通知和我希望每當新的推送通知來覆蓋舊的推送通知,在我的情況下,這是很好,當我的應用程序是在前臺,但當我把我的應用程序在後臺,它正在通知面板中創建新的通知。如何用通知面板中的新推送通知覆蓋新的推送通知
MyFirebaseMessagingService.class
Intent intent = new Intent(this,TabActivityClass.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
notificationBuilder.setSmallIcon(R.drawable.notification_logo)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
} else
{
notificationBuilder.setSmallIcon(R.drawable.notification_logo)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
}
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
我想表明在通知面板 只有最新的通知,謝謝您提前
只需使用相同的通知ID。它會用新的通知替換舊的通知。 –
@SamuelRobert我總是使用相同的通知ID,但它正在創建新的通知,我不想要這個 – Sunil
您是否在下面簽出我的答案? –