We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesPush KitAndroidcom.huawei.hms.pushClass SummaryRemoteMessage

RemoteMessage

  • Supported devices: phones and tablets
  • Supported operating systems: EMUI 9.1.0 or later and Android 9.0 or later
Expand

Class Info

public class RemoteMessage implements Parcelable

A message entity class. An app calls the onMessageReceived(RemoteMessage) method in HmsMessageService to receive messages pushed by the server and calls the send(RemoteMessage) method in HmsMessaging to send uplink messages.

The RemoteMessage.Notification class is an internal class for processing notification messages. If you have called the Push Kit server's open API to specify that notification messages are not displayed in the NC when your app is running in the foreground, the notification messages will be transparently transmitted to and processed by your app for display. In this case, the RemoteMessage message instance contains a RemoteMessage.Notification data instance. The member field definition in the Notification class is mapped to the field definition in the AndroidNotification Structure in Sending Downlink Messages. For apps running in the background or that do not exist, notification messages are displayed in the NC.

The RemoteMessage.Builder class is used to construct a RemoteMessage instance. All methods in this class take effect in EMUI 9.1 and later versions.

Nested Class Summary

Expand

Qualifier and Type

Class Name and Description

public static class

RemoteMessage.Notification

A notification message details class in RemoteMessage.

public static class

RemoteMessage.Builder

A constructor that is used to construct a RemoteMessage instance.

Public Method Summary

Expand

Qualifier and Type

Method Name and Description

String

getCollapseKey()

Obtains the collapse key of a message.

String

getData()

Obtains the payload of a message.

String

getFrom()

Obtains the source of a message.

String

getTo()

Obtains the recipient of a message.

String

getMessageId()

Obtains the ID of a message.

String

getMessageType()

Obtains the type of a message.

long

getSentTime()

Obtains the time when a message is sent from your server.

int

getTtl()

Obtains the maximum cache duration of a message.

RemoteMessage.Notification

getNotification()

Obtains the notification data instance from a message.

Map<String, String>

getDataOfMap()

Obtains the payload of a Map message.

String

getToken()

Obtains the token in a message.

String

getAnalyticInfo()

Obtains the tag of a message in a batch delivery task (bi_tag).

Map<String, String>

getAnalyticInfoMap()

Obtains the analysis data of the Map type.

Public Methods

getCollapseKey

Expand

Method

public String getCollapseKey()

Obtains the collapse key of a message. For details, please refer to the description of setCollapseKey in RemoteMessage.Builder.

Returns

Expand

Type

Description

String

A message collapse key.

getData

Expand

Method

public String getData()

Obtains the message payload of the string type.

Returns

Expand

Type

Description

String

A common string or a string in JSON format, for example, "your data" or "{'param1':'value1', 'param2':'value2'}". If you call the methods for modifying message content at the same time (call addData method and then setData), the content modified by addData will be overwritten by the content modified by setData. In this case, after the getData method is called, the content modified by setData is returned.

getFrom

Expand

Method

public String getFrom()

Obtains the source of a message. You can use this method to obtain the ID of the project to which a message sent by the Push Kit server belongs.

Returns

Expand

Type

Description

String

A message source.

getTo

Expand

Method

public String getTo()

Obtains the recipient of a message.

Returns

Expand

Type

Description

String

A message recipient.

getMessageId

Expand

Method

public String getMessageId()

Obtains the ID of a message.

Returns

Expand

Type

Description

String

A message ID.

getMessageType

Expand

Method

public String getMessageType()

Obtains the type of a message, which is set using setMessageType(String messageType) in RemoteMessage.Builder when you call send(RemoteMessage) in HmsMessaging to send uplink messages. The SDK transparently transmits the type to you. The message type is not set for data messages and notification messages, and the default value null is returned.

Returns

Expand

Type

Description

String

Message type that you set.

getSentTime

Expand

Method

public long getSentTime()

Obtains the time (in milliseconds) when a message is sent from your server.

Returns

Expand

Type

Description

long

The number of milliseconds from 00:00:00 on January 1, 1970 to the time when a message is sent from your server.

getTtl

Expand

Method

public int getTtl()

Obtains the maximum cache duration of a message, in seconds. For a message that is sent by the server, the value of ttl set in AndroidConfig Structure in Sending Downlink Messages is returned; for uplink messages, the value in setTtl() in RemoteMessage.Builder is returned.

Returns

Expand

Type

Description

int

The maximum cache duration of a message, in seconds.

getNotification

Expand

Method

public RemoteMessage.Notification getNotification()

Obtains the notification data from a message if notification data is configured in a message sent by your server.

Returns

Expand

Type

Description

RemoteMessage.Notification

A notification message instance.

getDataOfMap

Expand

Method

public Map<String, String> getDataOfMap()

Obtains the payload of a Map message. Different from the getData method, this method directly returns the instance of the Map data type.

Returns

Expand

Type

Description

Map<String, String>

If you set data to 123 in the message to be sent, the getData() method returns 123, and this method returns an empty Map-type instance. If you set data to {'param1':'value1'}, the getData() method returns the string in JSON format, for example, {'param1':'value1'}, and this method returns a Map-type instance containing {'param1':'value1'}.

getToken

Expand

Method

public String getToken()

Obtains the token in a message.

Returns

Expand

Type

Description

String

A push token.

getAnalyticInfo

Expand

Method

public String getAnalyticInfo()

Obtains the tag of a message in a batch delivery task (bi_tag).

Returns

Expand

Type

Description

String

A common string, for example, "your data".

getAnalyticInfoMap

Expand

Method

public Map<String, String> getAnalyticInfoMap()

Obtains the analysis data of the Map type. Different from the getAnalyticInfo method, this method directly returns the instance of the Map type.

Returns

Expand

Type

Description

Map<String, String>

If you set bi_tag to 123 in the message to be sent, the getAnalyticInfo method returns 123, and this method returns an empty Map-type instance. If you set bi_tag to {'param1':'value1'}, the getAnalyticInfo method returns the string in JSON format, for example, {'param1':'value1'}, and this method returns a Map-type instance containing {'param1':'value1'}.

Search in References
Enter a keyword.