Most visited

Recently visited

Added in API level 24

Notification.MessagingStyle.Message

public static final class Notification.MessagingStyle.Message
extends Object

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


Summary

Public constructors

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

构造函数

Public methods

String getDataMimeType()

获取Uri指向的数据的MIME类型

Uri getDataUri()

获取Uri指向消息的内容。

CharSequence getSender()

获取用于在消息传递体验中显示联系人姓名的文本

CharSequence getText()

获取用于此消息的文本,或者在设置了类型和内容Uri的情况下获取后备文本

long getTimestamp()

获取此消息到达的时间

Notification.MessagingStyle.Message setData(String dataMimeType, Uri dataUri)

为消息设置二进制blob数据和关联的MIME类型。

Inherited methods

From class java.lang.Object

Public constructors

Notification.MessagingStyle.Message

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

构造函数

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.

Public methods

getDataMimeType

Added in API level 24
String getDataMimeType ()

获取Uri指向的数据的MIME类型

Returns
String

getDataUri

Added in API level 24
Uri getDataUri ()

获取Uri指向消息的内容。 可以为null,在这种情况下使用。

Returns
Uri

也可以看看:

getSender

Added in API level 24
CharSequence getSender ()

获取用于在消息传递体验中显示联系人姓名的文本

Returns
CharSequence

getText

Added in API level 24
CharSequence getText ()

获取用于此消息的文本,或者在设置了类型和内容Uri的情况下获取后备文本

Returns
CharSequence

getTimestamp

Added in API level 24
long getTimestamp ()

获取此消息到达的时间

Returns
long

setData

Added in API level 24
Notification.MessagingStyle.Message setData (String dataMimeType, 
                Uri dataUri)

为消息设置二进制blob数据和关联的MIME类型。 在平台不支持MIME类型的情况下,将使用构造函数中提供的原始文本。

Parameters
dataMimeType String: The MIME type of the content. See for the list of supported MIME types on Android and Android Wear.
dataUri Uri: The uri containing the content whose type is given by the MIME type.

  1. Notification Listeners including the System UI need permission to access the data the Uri points to. The recommended ways to do this are:
  2. Store the data in your own ContentProvider, making sure that other apps have the correct permission to access your provider. The preferred mechanism for providing access is to use per-URI permissions which are temporary and only grant access to the receiving application. An easy way to create a ContentProvider like this is to use the FileProvider helper class.
  3. Use the system MediaStore. The MediaStore is primarily aimed at video, audio and image MIME types, however beginning with Android 3.0 (API level 11) it can also store non-media types (see MediaStore.Files for more info). Files can be inserted into the MediaStore using scanFile() after which a content:// style Uri suitable for sharing is passed to the provided onScanCompleted() callback. Note that once added to the system MediaStore the content is accessible to any app on the device.
Returns
Notification.MessagingStyle.Message this object for method chaining

Hooray!