目录

CLASS info
public final class RemoteMessage extends Object implements Parcelable

The RemoteMessage class is a message entity class that uses the onMessageReceived(RemoteMessage) method to receive messages sent by the server.

The RemoteMessage.Notification class is an internal class that indicates notification messages. When an app server sends a notification message, if the developer has configured the function on the server's open API that if the app is running in the foreground, the notification message is not displayed in the Notification Center (NC) but transparently transmitted to the app, the message is processed for display by the app. In this case, the RemoteMessage.Notification instance is contained in the RemoteMessage instance. The member fields defined in the Notification class map the fields defined in the AndroidNotification structure in Sending Messages from the HUAWEI Push Server. 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 the RemoteMessage instance.

Nested Class Summary

TypeNameDesc
ClassRemoteMessage.NotificationNotification message details in RemoteMessage.
ClassRemoteMessage.BuilderConstructor, which is used to construct a RemoteMessage instance.

Constant Summary

TypeNameDesc
intPRIORITY_UNKNOWNUnknown priority.
intPRIORITY_HIGHHigh priority.
intPRIORITY_NORMALNormal priority.

Public Method Summary

Return typeMethod name
StringgetCollapseKey()
Obtains the classification identifier (collapse key) of a message.
StringgetData()
Obtains the payload of a message.
Map<String, String>

getDataOfMap()

Obtains the payload of a Map message.

StringgetMessageId()
Obtains the ID of a message.
StringgetMessageType()
Obtains the type of a message.
RemoteMessage.NotificationgetNotification()
Obtains the notification data instance from a message.
intgetOriginalUrgency()
Obtains the message priority set by the app.
intgetUrgency()
Obtains the message priority set on the HUAWEI Push Kit server.
intgetTtl()
Obtains the maximum cache duration of a message.
longgetSentTime()
Obtains the time when a message is sent from the server.
StringgetTo()
Obtains the recipient of a message.
StringgetFrom()
Obtains the resource of a message.
String

getToken()

Obtains the token in a message.

Inherited Method Summary

android.os.Parcelablevoid

writeToParcel(Parcel dest, int flags)

Used in serialization and deserialization.

int

describeContents()

Used in serialization and deserialization.

Constants

Constant
public static final int PRIORITY_UNKNOWN
Constant Value: 0
Constant
public static final int PRIORITY_HIGH
Constant Value: 1
Constant
public static final int PRIORITY_NORMAL
Constant Value: 2

Public Methods

Method
public String getCollapseKey()
This method is used to obtain the classification identifier (collapse key) of a message.

Return

typedesc
StringMessage classification identifier.
Method
public String getData()
This method is used to obtain the payload of a message. Data obtained using the getData method is of the String type instead of the Map type of Java. You can determine the parsing rule of the data format. If data in the key-value format is transferred on the HUAWEI Push console, the data is converted into a JSON string and needs to be parsed. If data transmitted through HUAWEI Push is of high sensitivity and confidentiality, it is recommended that the message body be encrypted and decrypted by yourselves for security.

Return

typedesc
StringMessage payload. If data in the message is set to "123", the getData() method returns "123". If data is set to {"k", "v"}, the getData() method returns the character string {"k", "v"} in JSON format.
Method
public String getFrom()
This method is used to obtain the source of a message. When the Push Kit server sends a message, appid of the app to which the message belongs is set in the message body. You can use this method to obtain appid.

Return

typedesc
StringMessage source.
Method
public String getTo()
This method is used to obtain the recipient of a message.

Return

typedesc
StringMessage recipient.
Method
public String getMessageId()
This method is used to obtain the ID of a message.

Return

typedesc
StringMessage ID.
Method
public String getMessageType()
This method is used to obtain the type of a message.

Return

typedesc
StringMessage type set by the developer and transparently transmitted by the SDK.
Method
public long getSentTime()
This method is used to obtain the time (in milliseconds) when a message is sent from the server.

Return

typedesc
longNumber of milliseconds from 00:00:00 on January 1, 1970 to the time when a message is sent from the server.
Method
public int getTtl()
This method is used to obtain the maximum cache duration (in seconds) of a message. For a downstream message, the value of ttl in the AndroidConfig structure is returned.

Return

typedesc
intMaximum cache duration of a message, in seconds.
Method
public int getOriginalUrgency()
This method is used to obtain the message priority set by the app when it sends a message through an API of the HUAWEI Push Kit server. The priority is specified by AndroidConfig.urgency.

Return

typedesc
intMessage priority. For details, please refer to the definition in Constants of the RemoteMessage class.
Method
public int getUrgency()
This method is used to obtain the message priority set on the HUAWEI Push Kit server.

Return

typedesc
intMessage priority. For details, please refer to the definition in Constants of the RemoteMessage class.
Method
public RemoteMessage.Notification getNotification()
If notification data is configured in a message sent by the server, this method is called by an app to obtain the notification data from the message.

Return

typedesc
RemoteMessage.NotificationNotification message instance or null.
Method
public Map<String, String> getDataOfMap()
This method is used to obtain the payload of a Map message. Different from the getData method, this method directly returns a Map data instance or null (indicating an empty Map data instance).

Return

typedesc
Map<String, String>
If data is set to 123 in the message sent, the getData() method returns "123" and this method returns null. If data is set to {"k", "v"}, the getData() method returns {"k", "v"} in JSON format and this method returns a Map instance containing <k, v> in a specific format.
Method
public String getToken()
This method is used to obtain the token in a message.

Return

typedesc
StringToken.