Most visited

Recently visited

Added in API level 24

Notification.MessagingStyle

public static class Notification.MessagingStyle
extends Notification.Style

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


Helper类用于生成包含多个不同类型的多个来回消息的大格式通知。
如果平台不提供大幅面通知,则此方法不起作用。 用户将始终看到正常的通知视图。
这个类是一个“重建器”:它附着到一个Builder对象并修改它的行为,如下所示:


 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

通知本身将保留的最大消息数(显示的数字取决于平台)。

Inherited fields

From class android.app.Notification.Style

Public constructors

Notification.MessagingStyle(CharSequence userDisplayName)

Public methods

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

添加此通知显示的消息。

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

在此通知中添加一个 Notification.MessagingStyle.Message以供显示。

CharSequence getConversationTitle()

返回要在此对话中显示的标题。

List<Notification.MessagingStyle.Message> getMessages()

获取表示通知的 Message对象的列表

CharSequence getUserDisplayName()

返回用户发送的任何回复的名称

Notification.MessagingStyle setConversationTitle(CharSequence conversationTitle)

设置要在此对话中显示的标题。

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

通知本身将保留的最大消息数(显示的数字取决于平台)。

常量值:25(0x00000019)

Public constructors

Notification.MessagingStyle

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

Parameters
userDisplayName CharSequence: 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)

Public methods

addMessage

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

添加此通知显示的消息。 方便的调用,一个简单Notification.MessagingStyle.MessageaddMessage(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

也可以看看:

addMessage

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

在此通知中添加一个 Notification.MessagingStyle.Message以供显示。

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 ()

返回要在此对话中显示的标题。 可以是null ,应该用于一对一的对话

Returns
CharSequence

getMessages

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

获取表示通知的 Message对象的列表

Returns
List<Notification.MessagingStyle.Message>

getUserDisplayName

Added in API level 24
CharSequence getUserDisplayName ()

返回用户发送的任何回复的名称

Returns
CharSequence

setConversationTitle

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

设置要在此对话中显示的标题。 这应该只用于群组消息,并且不会进行一对一对话。

Returns
Notification.MessagingStyle this object for method chaining.

Hooray!