首页 > 解决方案 > 问题创建 NotificationCompat 任何打开的应用程序

问题描述

我有 NotificationCompat 粘性它会创建新的通知任何打开的应用程序,例如如果打开 10 次应用程序创建 10 个通知请帮助我

public void Notifa(){

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
  String offerChanelsName ="Shop Now Offers";
  String offerDescription ="Description Offer Names ";
  int offerChaqnelImportan = NotificationManager.IMPORTANCE_DEFAULT;

  NotificationChannel notificationChannel =new NotificationChannel(offerChannelId,offerChanelsName,offerChaqnelImportan);
  notificationChannel.setDescription(offerDescription);

  notificationManager.createNotificationChannel(notificationChannel);
}

builder = new NotificationCompat.Builder(context,offerChannelId);
builder.setSmallIcon(R.mipmap.ic_launcher)
        .setAutoCancel(false)
        .setCustomBigContentView(remoteViews)
        .setOngoing(true)
        .setContentIntent(pending);
notificationManager.notify(notifac_id,builder.build());

}

标签: javaandroidnotificationsandroid-notifications

解决方案


Tankyou @EugenPechanec 根据文档,如果您使用与以前相同的通知 ID 调用 NotificationManager.notify,则可以更新通知。只要你的 notifac_id 没有改变,它应该可以工作。——</p>


推荐阅读