Android Notifications: how to include extra text in top line

Viewed 1158

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!"
1 Answers

Found the answer!

It's the subtext:

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

Related