2

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:

enter image description here

Dick Lucas
  • 12,289
  • 14
  • 49
  • 76

1 Answers1

2

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.

Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50
  • Like in the example there are several different possible numbers that can show up. Is there a way to edit drawable resources on the fly, or would I have to draw out every number beforehand, and use a giant case switch statement to determine which drawable I want to use. That sounds like a horrible method, but unless I can edit those drawables from an activity, it seems like the only option. – Dick Lucas Jul 13 '13 at 19:29
  • 1
    I would just use the Canvas API to draw on a bitmap, this is easy and quick. There is a link in my post with an example. There is no need to create a lot of images – Ion Aalbers Jul 15 '13 at 05:20
  • I appreciate the help, but I believe the images for setSmallIcon must be predefined in the package. I don't think you have the ability to edit them on the fly. – Dick Lucas Jul 26 '13 at 20:34