Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/app/Notification.MessagingStyle#nestedclasses) \| [Constants](https://developer.android.com/reference/android/app/Notification.MessagingStyle#constants) \| [Inherited Fields](https://developer.android.com/reference/android/app/Notification.MessagingStyle#inhfields) \| [Ctors](https://developer.android.com/reference/android/app/Notification.MessagingStyle#pubctors) \| [Methods](https://developer.android.com/reference/android/app/Notification.MessagingStyle#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/Notification.MessagingStyle#inhmethods)

# Notification.MessagingStyle

*** ** * ** ***

` public static class Notification.MessagingStyle `   
` ` ` extends https://developer.android.com/reference/android/app/Notification.Style ` ` `

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [android.app.Notification.Style](https://developer.android.com/reference/android/app/Notification.Style) ||
|   | ↳ | android.app.Notification.MessagingStyle |

<br />

*** ** * ** ***

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.

If the app is targeting Android `https://developer.android.com/reference/android/os/Build.VERSION_CODES#P` and above, it is required to use the `https://developer.android.com/reference/android/app/Person` class in order to get an optimal rendering of the notification and its avatars. For conversations involving multiple people, the app should also make sure that it marks the conversation as a group with `https://developer.android.com/reference/android/app/Notification.MessagingStyle#setGroupConversation(boolean)`.

From Android `https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`, messaging style notifications that are associated with a valid conversation shortcut (via `https://developer.android.com/reference/android/app/Notification.Builder#setShortcutId(java.lang.String)`) are displayed in a dedicated conversation section in the shade above non-conversation alerting and silence notifications. To be a valid conversation shortcut, the shortcut must be a `https://developer.android.com/reference/android/content/pm/ShortcutInfo.Builder#setLongLived(boolean)` dynamic or cached sharing shortcut.

This class is a "rebuilder": It attaches to a Builder object and modifies its behavior. Here's an example of how this may be used:

```
Person user = new Person.Builder().setIcon(userIcon).setName(userName).build();
MessagingStyle style = new MessagingStyle(user)
     .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getPerson())
     .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson())
     .setGroupConversation(hasMultiplePeople());

Notification notif = new Notification.Builder()
    .setContentTitle("2 new messages with " + sender.toString())
    .setContentText(subject)
    .setSmallIcon(R.drawable.new_message)
    .setStyle(style)
    .build();
```
Note that this style doesn't display the large icon set via `https://developer.android.com/reference/android/app/Notification.Builder#setLargeIcon(android.graphics.drawable.Icon)`, except as a fallback group icon if the shortcut doesn't include one. It can, however, display images set via `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message#setData(java.lang.String,%20android.net.Uri)`.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message` An object representing a simple message or piece of media within a mixed-media message. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/app/Notification.MessagingStyle#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 `https://developer.android.com/reference/android/app/Notification.Style` ` protected https://developer.android.com/reference/android/app/Notification.Builder` `https://developer.android.com/reference/android/app/Notification.Style#mBuilder`

<br />

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#MessagingStyle(android.app.Person)(https://developer.android.com/reference/android/app/Person user) ` |
| ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#MessagingStyle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence userDisplayName) ` *This constructor is deprecated. use `MessagingStyle(Person)`* |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/app/Notification.MessagingStyle` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#addHistoricMessage(android.app.Notification.MessagingStyle.Message)(https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message message) ` Adds a `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message` for historic context in this notification. |
| ` https://developer.android.com/reference/android/app/Notification.MessagingStyle` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(java.lang.CharSequence,%20long,%20java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence text, long timestamp, https://developer.android.com/reference/java/lang/CharSequence sender) ` *This method was deprecated in API level 28. use `https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(java.lang.CharSequence,%20long,%20android.app.Person)`* |
| ` https://developer.android.com/reference/android/app/Notification.MessagingStyle` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(android.app.Notification.MessagingStyle.Message)(https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message message) ` Adds a `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message` for display in this notification. |
| ` https://developer.android.com/reference/android/app/Notification.MessagingStyle` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(java.lang.CharSequence,%20long,%20android.app.Person)(https://developer.android.com/reference/java/lang/CharSequence text, long timestamp, https://developer.android.com/reference/android/app/Person sender) ` Adds a message for display by this notification. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#getConversationTitle()() ` Return the title to be displayed on this conversation. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message>` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#getHistoricMessages()() ` Gets the list of historic `Message`s in the notification. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message>` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#getMessages()() ` Gets the list of `Message` objects that represent the notification. |
| ` https://developer.android.com/reference/android/app/Person` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#getUser()() ` |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#getUserDisplayName()() ` *This method was deprecated in API level 28. use `https://developer.android.com/reference/android/app/Notification.MessagingStyle#getUser()` instead* |
| ` boolean` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#isGroupConversation()() ` Returns `true` if this notification represents a group conversation, otherwise `false`. |
| ` https://developer.android.com/reference/android/app/Notification.MessagingStyle` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#setConversationTitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence conversationTitle) ` Sets the title to be displayed on this conversation. |
| ` https://developer.android.com/reference/android/app/Notification.MessagingStyle` | ` https://developer.android.com/reference/android/app/Notification.MessagingStyle#setGroupConversation(boolean)(boolean isGroupConversation) ` Sets whether this conversation notification represents a group. |

### Inherited methods

From class ` https://developer.android.com/reference/android/app/Notification.Style ` ` https://developer.android.com/reference/android/app/Notification` ` https://developer.android.com/reference/android/app/Notification.Style#build()() `

Calls `https://developer.android.com/reference/android/app/Notification.Builder#build()` on the Builder this Style is attached to.
` void` ` https://developer.android.com/reference/android/app/Notification.Style#checkBuilder()() ` ` https://developer.android.com/reference/android/widget/RemoteViews` ` https://developer.android.com/reference/android/app/Notification.Style#getStandardView(int)(int layoutId) ` ` void` ` https://developer.android.com/reference/android/app/Notification.Style#internalSetBigContentTitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence title) `

Overrides ContentTitle in the expanded form of the template.
` void` ` https://developer.android.com/reference/android/app/Notification.Style#internalSetSummaryText(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence cs) `

Set the first line of text after the detail section in the expanded form of the template.
` void` ` https://developer.android.com/reference/android/app/Notification.Style#setBuilder(android.app.Notification.Builder)(https://developer.android.com/reference/android/app/Notification.Builder builder) ` From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### MAXIMUM_RETAINED_MESSAGES

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final 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).

<br />

Constant Value: 25 (0x00000019)

## Public constructors

### MessagingStyle

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagingStyle (Person user)
```

<br />

<br />

| Parameters ||
|---|---|
| `user` | `Person`: Required - The person displayed for any messages that are sent by the user. Any messages added with `https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(android.app.Notification.MessagingStyle.Message)` who don't have a Person associated with it will be displayed as if they were sent by this user. The user also needs to have a valid name associated with it, which is enforced starting in Android `https://developer.android.com/reference/android/os/Build.VERSION_CODES#P`. This value cannot be `null`. <br /> |

### MessagingStyle

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MessagingStyle (CharSequence userDisplayName)
```

<br />

**This constructor is deprecated.**   

use `MessagingStyle(Person)`

<br />

<br />

| 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 `https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(android.app.Notification.MessagingStyle.Message)` This value cannot be `null`. <br /> |

## Public methods

### addHistoricMessage

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Adds a `https://developer.android.com/reference/android/app/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 `https://developer.android.com/reference/android/app/RemoteInput`.

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

<br />

| Parameters ||
|---|---|
| `message` | `Notification.MessagingStyle.Message`: The historic `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message` to be added <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Notification.MessagingStyle` | this object for method chaining <br /> |

### addMessage

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

**This method was deprecated in API level 28.**   

use `https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(java.lang.CharSequence,%20long,%20android.app.Person)`

Adds a message for display by this notification. Convenience call for a simple `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message` in `https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(android.app.Notification.MessagingStyle.Message)`.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: A `https://developer.android.com/reference/java/lang/CharSequence` to be displayed as the message content <br /> |
| `timestamp` | `long`: Time in milliseconds at which the message arrived <br /> |
| `sender` | `CharSequence`: A `https://developer.android.com/reference/java/lang/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 `https://developer.android.com/reference/android/app/Notification.MessagingStyle#getUserDisplayName()`. Should be unique amongst all individuals in the conversation, and should be consistent during re-posts of the notification. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Notification.MessagingStyle` | this object for method chaining <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message#Message(java.lang.CharSequence,%20long,%20java.lang.CharSequence)`

### addMessage

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Adds a `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message` for display in this notification.

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

Multiple Messages in a row with the same timestamp and sender may be grouped as a single message. This means an app should represent a message that has both an image and text as two Message objects, one with the image (and fallback text), and the other with the message text. For consistency, a text message (if any) should be provided after Uri content.

<br />

| Parameters ||
|---|---|
| `message` | `Notification.MessagingStyle.Message`: The `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message` to be displayed <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Notification.MessagingStyle` | this object for method chaining <br /> |

### addMessage

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Adds a message for display by this notification. Convenience call for a simple `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message` in `https://developer.android.com/reference/android/app/Notification.MessagingStyle#addMessage(android.app.Notification.MessagingStyle.Message)`.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: a `https://developer.android.com/reference/java/lang/CharSequence` to be displayed as the message content. This value cannot be `null`. <br /> |
| `timestamp` | `long`: time in milliseconds at which the message arrived <br /> |
| `sender` | `Person`: the `https://developer.android.com/reference/android/app/Person` who sent the message. Should be `null` for messages by the current user, in which case the platform will insert the user set in `MessagingStyle(Person)`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Notification.MessagingStyle` | this object for method chaining <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message#Message(java.lang.CharSequence,%20long,%20java.lang.CharSequence)`

### getConversationTitle

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CharSequence getConversationTitle ()
```

Return the title to be displayed on this conversation. May return `null`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | <br /> |

### getHistoricMessages

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<Notification.MessagingStyle.Message> getHistoricMessages ()
```

Gets the list of historic `Message`s in the notification.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message>` | <br /> |

### getMessages

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<Notification.MessagingStyle.Message> getMessages ()
```

Gets the list of `Message` objects that represent the notification.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/Notification.MessagingStyle.Message>` | <br /> |

### getUser

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Person getUser ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Person` | the user to be displayed for any replies sent by the user. This value cannot be `null`. <br /> |

### getUserDisplayName

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CharSequence getUserDisplayName ()
```

<br />

**This method was deprecated in API level 28.**   

use `https://developer.android.com/reference/android/app/Notification.MessagingStyle#getUser()` instead

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | <br /> |

### isGroupConversation

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isGroupConversation ()
```

Returns `true` if this notification represents a group conversation, otherwise `false`.

If the application that generated this `https://developer.android.com/reference/android/app/Notification.MessagingStyle` targets an SDK version less than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#P`, this method becomes dependent on whether or not the conversation title is set; returning `true` if the conversation title is a non-null value, or `false` otherwise. From `https://developer.android.com/reference/android/os/Build.VERSION_CODES#P` forward, this method returns what's set by `https://developer.android.com/reference/android/app/Notification.MessagingStyle#setGroupConversation(boolean)` allowing for named, non-group conversations.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/Notification.MessagingStyle#setConversationTitle(java.lang.CharSequence)`

### setConversationTitle

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Notification.MessagingStyle setConversationTitle (CharSequence conversationTitle)
```

Sets the title to be displayed on this conversation. May be set to `null`.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`, this conversation title will be ignored if a valid shortcutId is added via `https://developer.android.com/reference/android/app/Notification.Builder#setShortcutId(java.lang.String)`. In this case, `https://developer.android.com/reference/android/content/pm/ShortcutInfo#getLongLabel()` (or, if missing, `https://developer.android.com/reference/android/content/pm/ShortcutInfo#getShortLabel()`) will be shown as the conversation title instead.

This API's behavior was changed in SDK version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#P`. If your application's target version is less than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#P`, setting a conversation title to a non-null value will make `https://developer.android.com/reference/android/app/Notification.MessagingStyle#isGroupConversation()` return `true` and passing `null` will make it return `false`. In `https://developer.android.com/reference/android/os/Build.VERSION_CODES#P` and beyond, use `https://developer.android.com/reference/android/app/Notification.MessagingStyle#setGroupConversation(boolean)` to set group conversation status.

<br />

| Parameters ||
|---|---|
| `conversationTitle` | `CharSequence`: title displayed for this conversation. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Notification.MessagingStyle` | this object for method chaining <br /> |

### setGroupConversation

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Notification.MessagingStyle setGroupConversation (boolean isGroupConversation)
```

Sets whether this conversation notification represents a group. If the app is targeting Android P, this is required if the app wants to display the largeIcon set with `https://developer.android.com/reference/android/app/Notification.Builder#setLargeIcon(android.graphics.Bitmap)`, otherwise it will be hidden.

<br />

| Parameters ||
|---|---|
| `isGroupConversation` | `boolean`: `true` if the conversation represents a group, `false` otherwise. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Notification.MessagingStyle` | this object for method chaining <br /> |