Skip to content

Most visited

Recently visited

navigation

Notification.MessagingStyle

public static class Notification.MessagingStyle
extends Notification.Style

java.lang.Object
   ↳ android.app.Notification.Style
     ↳ android.app.Notification.MessagingStyle


Helper class for generating large-format notifications that include multiple back-and-forth messages of varying types between any number of people.
If the platform does not provide large-format notifications, this method has no effect. The user will always see the normal notification view.
This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:


 Notification noti = new Notification.Builder()
     .setContentTitle("2 new messages wtih " + sender.toString())
     .setContentText(subject)
     .setSmallIcon(R.drawable.new_message)
     .setLargeIcon(aBitmap)
     .setStyle(new Notification.MessagingStyle(resources.getString(R.string.reply_name))
         .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender())
         .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender()))
     .build();
 

Summary

Nested classes

class Notification.MessagingStyle.Message

 

Constants

int MAXIMUM_RETAINED_MESSAGES

The maximum number of messages that will be retained in the Notification itself (the number displayed is up to the platform).

Inherited fields

From class android.app.Notification.Style

Public constructors

Notification.MessagingStyle(CharSequence userDisplayName)

Public methods

Notification.MessagingStyle addHistoricMessage(Notification.MessagingStyle.Message message)

Adds a Notification.MessagingStyle.Message for historic context in this notification.

Notification.MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender)

Adds a message for display by this notification.

Notification.MessagingStyle addMessage(Notification.MessagingStyle.Message message)

Adds a Notification.MessagingStyle.Message for display in this notification.

CharSequence getConversationTitle()

Return the title to be displayed on this conversation.

List<Notification.MessagingStyle.Message> getHistoricMessages()

Gets the list of historic Messages in the notification.

List<Notification.MessagingStyle.Message> getMessages()

Gets the list of Message objects that represent the notification

CharSequence getUserDisplayName()

Returns the name to be displayed for any replies sent by the user

Notification.MessagingStyle setConversationTitle(CharSequence conversationTitle)

Sets the title to be displayed on this conversation.

Inherited methods

From class android.app.Notification.Style
From class java.lang.Object

Constants

MAXIMUM_RETAINED_MESSAGES

added in API level 24
int MAXIMUM_RETAINED_MESSAGES

The maximum number of messages that will be retained in the Notification itself (the number displayed is up to the platform).

Constant Value: 25 (0x00000019)

Public constructors

Notification.MessagingStyle

added in API level 24
Notification.MessagingStyle (CharSequence userDisplayName)

Parameters
userDisplayName CharSequence: Required - the name to be displayed for any replies sent by the user before the posting app reposts the notification with those messages after they've been actually sent and in previous messages sent by the user added in addMessage(Notification.MessagingStyle.Message)

This value must never be null.

Public methods

addHistoricMessage

added in API level 26
Notification.MessagingStyle addHistoricMessage (Notification.MessagingStyle.Message message)

Adds a Notification.MessagingStyle.Message for historic context in this notification.

Messages should be added as historic if they are not the main subject of the notification but may give context to a conversation. The system may choose to present them only when relevant, e.g. when replying to a message through a RemoteInput.

The messages should be added in chronologic order, i.e. the oldest first, the newest last.

Parameters
message Notification.MessagingStyle.Message: The historic Notification.MessagingStyle.Message to be added

Returns
Notification.MessagingStyle this object for method chaining

addMessage

added in API level 24
Notification.MessagingStyle addMessage (CharSequence text, 
                long timestamp, 
                CharSequence sender)

Adds a message for display by this notification. Convenience call for a simple Notification.MessagingStyle.Message in addMessage(Notification.MessagingStyle.Message).

Parameters
text CharSequence: A CharSequence to be displayed as the message content

timestamp long: Time at which the message arrived

sender CharSequence: A CharSequence to be used for displaying the name of the sender. Should be null for messages by the current user, in which case the platform will insert getUserDisplayName(). Should be unique amongst all individuals in the conversation, and should be consistent during re-posts of the notification.

Returns
Notification.MessagingStyle this object for method chaining

See also:

addMessage

added in API level 24
Notification.MessagingStyle addMessage (Notification.MessagingStyle.Message message)

Adds a Notification.MessagingStyle.Message for display in this notification.

The messages should be added in chronologic order, i.e. the oldest first, the newest last.

Parameters
message Notification.MessagingStyle.Message: The Notification.MessagingStyle.Message to be displayed

Returns
Notification.MessagingStyle this object for method chaining

getConversationTitle

added in API level 24
CharSequence getConversationTitle ()

Return the title to be displayed on this conversation. Can be null and should be for one-on-one conversations

Returns
CharSequence

getHistoricMessages

added in API level 26
List<Notification.MessagingStyle.Message> getHistoricMessages ()

Gets the list of historic Messages in the notification.

Returns
List<Notification.MessagingStyle.Message>

getMessages

added in API level 24
List<Notification.MessagingStyle.Message> getMessages ()

Gets the list of Message objects that represent the notification

Returns
List<Notification.MessagingStyle.Message>

getUserDisplayName

added in API level 24
CharSequence getUserDisplayName ()

Returns the name to be displayed for any replies sent by the user

Returns
CharSequence

setConversationTitle

added in API level 24
Notification.MessagingStyle setConversationTitle (CharSequence conversationTitle)

Sets the title to be displayed on this conversation. This should only be used for group messaging and left unset for one-on-one conversations.

Returns
Notification.MessagingStyle this object for method chaining.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.