Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification: add text after app's name, before when

Does anyone know how we can add text, to the right of the app's name in a notification and before the timestamp(when)? preview

like image 998
Keivan Noroozi Avatar asked Mar 20 '18 20:03

Keivan Noroozi


People also ask

What is Channel_id?

ChannelId is a unique String to identify each NotificationChannel and is used in Notification. Builder (line 7) when constructing the Notification object. NotificationChannel settings, except channel name and description text, are immutable after it is submitted to NotificationManager at line 5.

What are the two types of notifications?

Android proposes several types of notifications to inform the user: notifications in the system bar. sound notifications.

Which attribute is used to set the title for giving notification?

setContentTitle(): It is used to set the title of notification. setContentText(): It is used to set the text message.

How do I use NotificationListenerService?

To use NotificationListenerService, we need to create a java file which extends NotificationListenerService and implement two callback methods. Both methods have a parameter named “sbn”, which is an object of StatusBarNotification class. StatusBarNotification provides necessary information about Notifications.


1 Answers

in Notification.Builder there is a method called setSubText().

You can pass the message to display as String.

Link to documentation : https://developer.android.com/reference/android/app/Notification.Builder.html#setSubText(java.lang.CharSequence)

Notification noti = new Notification.Builder(mContext)
     .setContentTitle(AppName)
     .setContentText(message)
     .setSmallIcon(R.drawable.logo)
     .setSubText(senders_mail)
     .build();
like image 120
Nuwan Alawatta Avatar answered Oct 29 '22 14:10

Nuwan Alawatta