How to properly update a notification post api 11?

后端 未结 4 816
野性不改
野性不改 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:12

    I'm guessing (since I had the same trouble just now) that you are using a RemoteView in your notification. I managed to update the notification without it flashing like this:

    RemoteViews views;
    if( this.mNotification == null) {
        views = new RemoteViews(getPackageName(), R.layout.notification);
        this.mNotification = new Notification.Builder(this)
            .setContent(views)
            .setSmallIcon(R.drawable.status_icon)
            .setContentIntent(mNotificationAction)
            .setOngoing(true)
            .setOnlyAlertOnce(true)
            .getNotification();
    } else {
        views = this.mNotification.contentView;
    }
    

    Thanks to @seanmonstar for answering Refresh progress bar in notification bar.

提交回复
热议问题