-2

I'd like to ask how it is possible to show text permanently in the notification bar? The ticker set by the setTicker() method disappears after a few seconds.

My goal is to show the current temperature in the notification bar. What would be the best solution to do this? Maybe there's a way to pass text to the setSmallIcon() method?

Here's my notification code:

NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getApplicationContext());
            notBuilder.setContentText("text");
            notBuilder.setContentTitle("title");
            notBuilder.setSmallIcon(android.R.color.transparent);
            notBuilder.setTicker("ticker");
            notBuilder.setOngoing(true);
            int notID = 8;
            NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            nm.notify(notID, notBuilder.build());

(is there a better solution to hide the small icon? it's transparent this way but still takes up the place)

Thanks in advance!

2 Answers2

0

Set this flag to your builder notBuilder.setOngoing(true);. This will show the notification permanently as far as icon is concerned set a small transparent image.

You can try notBuilder.setSmallIcon(android.R.color.transparent);

CodeWarrior
  • 5,026
  • 6
  • 30
  • 46
  • It is set, the notification stays permanent, but the text (set by the setTicker() method) still disappears. I want the text permanent, similar to the small icon. – earthw0rmjim Jul 12 '14 at 09:07
0

It's only possible to show a permanent icon in the status bar. The text set by the ticker can't be permanent and appears only for a period if the notification shows the first time. This is by design because the user usually don't want a permanent message which "hides" the status bar.

To hide the small icon completely you could use NotificationBuilder.setPriority(int) with the flag Notification.PRIORITY_MIN. This way the notification will be reduced to a minimum, which includes the hiding of the icon. But this method is only available in API 16+. Below this level you can set a transperent icon (what you already did), but the space for the icon acts like a placeholder and can't be deleted. Maybe this answer is helpful for your situation, but it just moves the icon space to another area.

Community
  • 1
  • 1
Steve Benett
  • 12,843
  • 7
  • 59
  • 79