How to properly update a notification post api 11?

后端 未结 4 784
野性不改
野性不改 2021-02-02 13:14
  • Before Notification.Builder came into existence the way to update a notification that was already in the notification tray was to call setLatestEventInfo()

4条回答
  •  甜味超标
    2021-02-02 14:00

    The solution described here works well: Updating an ongoing notification quietly

    The key is to use to reuse the builder and setOnlyAlertOnce(true):

    if (firstTime) {
      mBuilder.setSmallIcon(R.drawable.icon)
      .setContentTitle("My Notification") 
      .setOnlyAlertOnce(true); 
      firstTime = false;
    } 
    mBuilder.setContentText(message)
    .setProgress(100, progress, true);
    
    mNotificationManager.notify(mNotificationId, mBuilder.build());
    

提交回复
热议问题