NotificationCompat.MessagingStyle.Message

Added in 1.1.0

public final class NotificationCompat.MessagingStyle.Message


Summary

Public constructors

Message(
    @Nullable CharSequence text,
    long timestamp,
    @Nullable Person person
)

Creates a new Message with the given text, timestamp, and sender.

Message(
    @Nullable CharSequence text,
    long timestamp,
    @Nullable CharSequence sender
)

This method is deprecated.

Use the alternative constructor instead.

Public methods

@Nullable String

Get the MIME type of the data pointed to by the URI.

@Nullable Uri

Get the the Uri pointing to the content of the message.

@NonNull Bundle

Get the extras Bundle for this message.

@Nullable Person

Returns the Person sender of this message.

@Nullable CharSequence

This method is deprecated.

Use getPerson

@Nullable 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 in ms since Unix epoch.

@NonNull NotificationCompat.MessagingStyle.Message
setData(@Nullable String dataMimeType, @Nullable Uri dataUri)

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

Public constructors

Message

Added in 1.1.0
public Message(
    @Nullable CharSequence text,
    long timestamp,
    @Nullable Person person
)

Creates a new Message with the given text, timestamp, and sender.

Parameters
@Nullable CharSequence text

A CharSequence to be displayed as the message content

long timestamp

Time at which the message arrived in ms since Unix epoch

@Nullable Person person

A Person whose getName value is used as the display name for the sender. This should be null for messages by the current user, in which case, the platform will insert getUserDisplayName. A Person's key should be consistent during re-posts of the notification.

Message

Added in 1.1.0
Deprecated in 1.1.0
public Message(
    @Nullable CharSequence text,
    long timestamp,
    @Nullable CharSequence sender
)

Constructor

Parameters
@Nullable CharSequence text

A CharSequence to be displayed as the message content

long timestamp

Time at which the message arrived in ms since Unix epoch

@Nullable CharSequence sender

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 1.1.0
public @Nullable String getDataMimeType()

Get the MIME type of the data pointed to by the URI.

getDataUri

Added in 1.1.0
public @Nullable Uri getDataUri()

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

getExtras

Added in 1.1.0
public @NonNull Bundle getExtras()

Get the extras Bundle for this message.

getPerson

Added in 1.1.0
public @Nullable Person getPerson()

Returns the Person sender of this message.

getSender

Added in 1.1.0
Deprecated in 1.1.0
public @Nullable CharSequence getSender()

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

getText

Added in 1.1.0
public @Nullable CharSequence getText()

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 1.1.0
public long getTimestamp()

Get the time at which this message arrived in ms since Unix epoch.

setData

Added in 1.1.0
public @NonNull NotificationCompat.MessagingStyle.Message setData(@Nullable String dataMimeType, @Nullable Uri dataUri)

Sets a binary blob of data and an associated MIME type for a message. In the case where the platform doesn't support the MIME type, the original text provided in the constructor will be used.

Parameters
@Nullable String dataMimeType

The MIME type of the content. See isMimeTypeSupported for a list of supported image MIME types.

@Nullable Uri dataUri

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
@NonNull NotificationCompat.MessagingStyle.Message

this object for method chaining