5

These are 2 notifications on Android 7+:


  • in the top line, this one presents: the icon, the app name, and the time enter image description here


  • in the top line, this one presents: the icon, the app name, an extra text (in the case of Gmail is the account email address), and the time enter image description here


Can anyone explain how to include the extra text between the app name and the notification time, as shown in the Gmail notification?

Is there a method of NotificationCompat.Builder to set that text?

   NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NotificationChannels.TRIPS_CHANNEL_ID)
      .setSmallIcon(ICON_DRAWABLE)
      .setColor(TITLE_COLOR)
      .setContentTitle(FIRST_LINE_TEXT) // "Remote input"
      .setContentText(SECOND_LINE_TEXT); // "Try typing some text!"
Daniele B
  • 19,801
  • 29
  • 115
  • 173
  • 1
    can the person that just downvoted give an explanation, please? – Daniele B Nov 22 '17 at 18:06
  • Wasn't me but I assume that they felt you did not perform a minimal on self research on this subject. You posted no code showing that you have attempted to solve the "problem" yourself. – Barns Nov 22 '17 at 18:18
  • 1
    @Barns I have included some code. Let's see if that helps. – Daniele B Nov 22 '17 at 18:23
  • @Barns can you help me by upvoting the question? thanks! – Daniele B Nov 22 '17 at 18:25
  • So you have try the above code (which isn't quite complete -- how is the notification being posted?) what is the result you are seeing? Is the "FIRST_LINE_TEXT" and/or "SECOND_LINE_TEXT" not being displayed? – Barns Nov 22 '17 at 18:30
  • I have just included the code concerning the UI – Daniele B Nov 22 '17 at 18:32
  • Sorry my Solution didn't help you on your problem. I guess it just isn't clear to me exactly what you are expecting-- Good luck finding the right solution. You will probably have better luck getting a response if I remove my suggestion. – Barns Nov 22 '17 at 19:07
  • @Barns I have updated my question, to clarify what I mean – Daniele B Nov 22 '17 at 19:34
  • 1
    Maybe take a look at the most popular answer from this post using `RemoteView` :: https://stackoverflow.com/questions/41888161/how-to-create-a-custom-notification-layout-in-android – Barns Nov 22 '17 at 20:07
  • 1
    @Barns actually one of the answers there gave me the hint! It is `setSubText()`!!! – Daniele B Nov 22 '17 at 20:12

1 Answers1

8

Found the answer!

It's the subtext:

.setSubText("text to show next to app name")

Daniele B
  • 19,801
  • 29
  • 115
  • 173
  • 1
    would be nice if Google added this to their guide https://developer.android.com/guide/topics/ui/notifiers/notifications – lasec0203 Jul 18 '20 at 20:28