Added in API level 24

Message


class Message
kotlin.Any
   ↳ android.app.Notification.MessagingStyle.Message

Summary

Public constructors
Message(text: CharSequence, timestamp: Long, sender: Person?)

Constructor

Message(text: CharSequence!, timestamp: Long, sender: CharSequence!)

Constructor

Public methods
String!

Get the MIME type of the data pointed to by the Uri

Uri!

Get the Uri pointing to the content of the message.

Bundle!

Get the extras Bundle for this message.

static MutableList<Notification.MessagingStyle.Message!>

Returns a list of messages read from the given bundle list, e.

CharSequence!

Get the text used to display the contact's name in the messaging experience

Person?

Get the sender associated with this message.

CharSequence!

Get the text to be used for this message, or the fallback text if a type and content Uri have been set

Long

Get the time at which this message arrived

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

Sets a binary blob of data and an associated MIME type for a message.

Public constructors

Message

Added in API level 28
Message(
    text: CharSequence,
    timestamp: Long,
    sender: Person?)

Constructor

Parameters
text CharSequence: A CharSequence to be displayed as the message content This value cannot be null.
timestamp Long: Time at which the message arrived
sender Person?: The 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).

The person provided should contain an Icon, set with Person.Builder.setIcon(Icon) and also have a name provided with Person.Builder.setName(CharSequence). If multiple users have the same name, consider providing a key with Person.Builder.setKey(String) in order to differentiate between the different users.

Message

Added in API level 24
Message(
    text: CharSequence!,
    timestamp: Long,
    sender: CharSequence!)

Deprecated: use Message(CharSequence, long, Person)

Constructor

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 MessagingStyle.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
fun getDataMimeType(): String!

Get the MIME type of the data pointed to by the Uri

getDataUri

Added in API level 24
fun getDataUri(): Uri!

Get the Uri pointing to the content of the message. Can be null, in which case {@see #getText()} is used.

getExtras

Added in API level 26
fun getExtras(): Bundle!

Get the extras Bundle for this message.

getMessagesFromBundleArray

Added in API level 30
static fun getMessagesFromBundleArray(bundles: Array<Parcelable!>?): MutableList<Notification.MessagingStyle.Message!>

Returns a list of messages read from the given bundle list, e.g. EXTRA_MESSAGES or EXTRA_HISTORIC_MESSAGES.

Parameters
bundles Array<Parcelable!>?: This value may be null.
Return
MutableList<Notification.MessagingStyle.Message!> This value cannot be null.

getSender

Added in API level 24
Deprecated in API level 28
fun getSender(): CharSequence!

Deprecated: use getSenderPerson()

Get the text used to display the contact's name in the messaging experience

getSenderPerson

Added in API level 28
fun getSenderPerson(): Person?

Get the sender associated with this message.

Return
Person? This value may be null.

getText

Added in API level 24
fun getText(): CharSequence!

Get the text to be used for this message, or the fallback text if a type and content Uri have been set

getTimestamp

Added in API level 24
fun getTimestamp(): Long

Get the time at which this message arrived

setData

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

Sets a binary blob of data and an associated MIME type for a message. In the case where the platform or the UI state doesn't support the MIME type, the original text provided in the constructor will be used. When this data can be presented to the user, the original text will only be used as accessibility text.

Parameters
dataMimeType String!: The MIME type of the content. See android.graphics.ImageDecoder#isMimeTypeSupported(String) for a list of supported image MIME types.
dataUri Uri!: The uri containing the content whose type is given by the MIME type.

Notification Listeners including the System UI need permission to access the data the Uri points to. The recommended ways to do this are:

  1. 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.
  2. 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.
Return
Notification.MessagingStyle.Message! this object for method chaining