目录

CLASS info
public static class RemoteMessage.Builder extends Object
Constructs a RemoteMessage instance.

Public Constructor Summary

Constructor name

public RemoteMessage.Builder(String to) 

Argument constructor of the RemoteMessage.Builder class.

Public Method Summary

Return typeMethod name
RemoteMessage.Builder

addData(String key, String value)

Adds key-value pair data to a message.

RemoteMessage.Builder

setData(Map<String, String> map)

Sets Map data to a message.

RemoteMessage.Builder

clearData()

Deletes message data.

RemoteMessage.Builder

setMessageId(String messageId)

Sets the ID of a message.

RemoteMessage.Builder

setMessageType(String messageType)

Sets the type of a message.

RemoteMessage.Builder

setTtl(int ttl)

Sets the maximum cache duration of a message, in seconds.

RemoteMessage.Builder

setCollapseKey(String collapseKey)

Sets the classification identifier of a message.

RemoteMessage.Builder

setSendMode(int sendMode)

Sets whether to enable the message cache and resending capability of the Push Kit client.

RemoteMessage.Builder

setReceiptMode(int receiptMode)

Sets the receipt capability after an uplink message is sent to the app server.

RemoteMessage

build()

Constructs a RemoteMessage instance.

Public Constructors

constructor
public Builder(String to)

Argument constructor of the RemoteMessage.Builder class to construct an object with to as the input parameter

Parameters

Parameter nameParameter desc
to

For an uplink message, the value is always push.hcm.upstream.

Public Methods

Method
public RemoteMessage.Builder addData(String key, String value)
This method is used to add key-value pair data to a message.

Parameters

Parameter nameParameter desc
keyKey in a key-value pair, for example, name.
valueValue in a key-value pair, for example, ZhangSan.


Throws

Throw nameThrow desc
IllegalArgumentExceptionException thrown when key is null.
Method
public RemoteMessage.Builder setData(Map<String, String> map)
This method is used to specify message data to Map data. All existing data will be deleted.

Parameters

Parameter nameParameter desc
mapMap data provided by Java.
Method
public RemoteMessage.Builder clearData()
This method is used to delete the message data of the Builder instance.
Method
public RemoteMessage.Builder setMessageId(String messageId)
This method is used to set the ID of a message.

Parameters

Parameter nameParameter desc
messageIdMessage ID, which is generated by an app and is unique for each message.
Method
public RemoteMessage.Builder setMessageType(String messageType)
This method is used to set the type of an upstream message or device group message sent through the send(RemoteMessage) method. The message type is transparently transmitted by the SDK.

Parameters

Parameter nameParameter desc
messageTypeMessage type specified by the developer.
Method
public RemoteMessage.Builder setTtl(int ttl)
This method is used to set the maximum cache duration of an offline message, in seconds. If the duration is set to 0, the message is resent immediately instead of being cached. If the destination device cannot be connected, the message will be discarded.

Parameters

Parameter nameParameter desc
ttlMaximum cache duration of an offline message set for HUAWEI Push Kit, in seconds. The duration can be set to 15 days at most.


Throws

Throw nameThrow desc
IllegalArgumentExceptionThe value of the input parameter ttl must be within the range [0,1296000]. Otherwise, the system throws IllegalArgumentException, indicating that invalid parameters exist.
Method
public RemoteMessage.Builder setCollapseKey(String collapseKey)
This method is used to set the classification identifier of a message, which is used to control the overwriting function of offline messages. For cached offline messages, the latest message with the same classification identifier overwrites earlier messages.When HUAWEI Push Kit detects that the destination device is offline, it caches messages to be sent based on the messages' TTL. After the device goes online, HUAWEI Push Kit delivers the cached messages to the device.

Parameters

Parameter nameParameter desc
collapseKeyIf you set collapse_key to -1, all offline messages of the app are sent to the device.If you set collapse_key to 0, offline messages of the app sent to the device are determined by the default policy of HUAWEI Push. Generally, only the latest offline message is sent to the device.You can set collapse_key to a value ranging from 1 to 100 to group messages. For example, if you send 10 messages and set collapse_key to 1 for the first five messages and to 2 for the rest, the latest offline message whose value of collapse_key is 1 and the latest offline message whose value of collapse_key is 2 are sent to the device.
Method
public RemoteMessage.Builder setSendMode(int sendMode)
Sets whether to enable the message cache and resending capability of the Push Kit client. If this parameter is not set, messages cannot be cached or resent. For example, when the network is unavailable, messages are directly discarded.

Parameters

Parameter nameParameter desc

sendMode

The value can be 0 or 1. The value 1 indicates that the cache and resending capability is enabled.


Throws

Throw nameThrow desc
IllegalArgumentException

Exception thrown if the value is not 0 or 1.

Method
public RemoteMessage.Builder setReceiptMode(int receiptMode)

Sets the receipt capability after an uplink message is sent to the app server. That is, if an uplink message sent by the app is successfully sent to the app server, the server will respond and send a receipt to the app through the onMessageDelivered method of the HmsMessageService class.

Parameters

Parameter nameParameter desc

receiptMode

The value can be 0 or 1. The value 1 indicates that the receipt capability is enabled after messages are sent.


Throws

Throw nameThrow desc
IllegalArgumentException

Exception thrown if the value is not 0 or 1.

Method
public RemoteMessage build()
This method is used to construct a RemoteMessage instance.

Throws

Throw nameThrow desc
ExceptionException that occurs when the build method is called. You can obtain the exception description by using the Exception.getMessage() method.


Return

typedesc
RemoteMessage

Returns a RemoteMessage instance.