2

I want to show text of a notification in status bar like in this picture:

enter image description here

But instead I get the following:

enter image description here

So, as you can see, I can't show the text in status bar, only icon. My code looks like this:

Notification notification = new Notification.Builder(this) .setSmallIcon(R.drawable.icon) .setContentTitle("My app") .setTicker("Alex: hey, want to grab lunch?") .setWhen(System.currentTimeMillis()) .setContentText("Alex: hey, want to grab lunch?") .setPriority(Notification.PRIORITY_MAX) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); 

How do I correct that?

1 Answer 1

1

It depends entirely on what version of Android the app is run on. If it's Lollipop (5.0) or above, then no, the text will not appear in the status bar. From the documentation (my bold):

Text that summarizes this notification for accessibility services. As of the L release, this text is no longer shown on screen, but it is still useful to accessibility services (where it serves as an audible announcement of the notification's appearance).

So it's still worth having as it'll be read out to anyone who uses text-to-speech accessibility services on their phone. It just won't work in the way you're expecting it to in your question.

Alternatively, if you want your notification to appear briefly as a heads-up notification, you can set your notification's priority to PRIORITY_HIGH (up to API 26):

Notification notification = new Notification.Builder(this) ... .setPriority(Notification.PRIORITY_HIGH) .build(); 

You may also need to use a NotificationCompat.Builder rather than Notification.Builder if this doesn't work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.