Possible to continuously update text in the notifi

2020-07-24 06:44发布

问题:

I would like a to place persistent text in the notification area that updates once every second. setTicker() in the NotificationCompat.Builder class will not work, because it hides everything else in the notification area. I am only looking to place text there that is a few characters long, taking up only a small piece of the notification area.

One way I think this can be done is by calling setSmallIcon(), and somehow using this small icon area to display text. I took a screenshot of an app's notification that I believe to be using this strategy. Notice the 165 KB/s:

回答1:

You shouldn't use the ticker text of the notification to update the user. This text is shown when the notification is posted.

Like the screenshot it uses setSmallIcon like you mentioned.

You can create a bitmap and draw text on with the canvas API, then updating your current ongoing notification

Example how to draw text on bitmap

This will change the icon in the statusbar and visible for the user.