Notification.MessagingStyle.Message  |  API reference  |  Android Developers


public static final class Notification.MessagingStyle.Message
extends Object



An object representing a simple message or piece of media within a mixed-media message.

This object can only represent text or a single binary piece of media. For apps which support mixed-media messages (e.g. text + image), multiple Messages should be used, one to represent each piece of the message, and they should all be given the same timestamp. For consistency, a text message should be added last of all Messages with the same timestamp.

Summary

Public constructors

Message(CharSequence text, long timestamp, Person sender)

Constructor

Message(CharSequence text, long timestamp, CharSequence sender)

This constructor is deprecated. use Message(CharSequence, long, Person)

Public methods

String getDataMimeType()

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

Uri getDataUri()

Get the Uri pointing to the content of the message.

Bundle getExtras()

Get the extras Bundle for this message.

static List<Notification.MessagingStyle.Message> getMessagesFromBundleArray(Parcelable[] bundles)

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

CharSequence getSender()

This method was deprecated in API level 28. use getSenderPerson()

Person getSenderPerson()

Get the sender associated with this message.

CharSequence getText()

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

long getTimestamp()

Get the time at which this message arrived

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

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

Inherited methods

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(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 wait(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 wait()

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

Public constructors

Message

public Message (CharSequence text, 
                long timestamp, 
                Person sender)

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

public Message (CharSequence text, 
                long timestamp, 
                CharSequence sender)

This constructor is 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

public String getDataMimeType ()

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

Returns
String

getDataUri

public Uri getDataUri ()

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

Returns
Uri
public Bundle getExtras ()

Get the extras Bundle for this message.

Returns
Bundle

getSender

public CharSequence getSender ()

This method was deprecated in API level 28.
use getSenderPerson()

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

Returns
CharSequence

getSenderPerson

public Person getSenderPerson ()

Get the sender associated with this message.

Returns
Person This value may be null.

getText

public CharSequence getText ()

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

Returns
CharSequence

getTimestamp

public long getTimestamp ()

Get the time at which this message arrived

Returns
long

setData

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

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.
Returns
Notification.MessagingStyle.Message this object for method chaining