目录

RemoteMessage

Class Info

public class RemoteMessage implements Parcelable

RemoteMessage类是一个消息实体类,应用通过HmsMessageService中的onMessageReceived(RemoteMessage)方法接收服务端推送的消息,通过HmsMessaging中的send(RemoteMessage)方法发送上行消息。

RemoteMessage.Notification类是一个内部类,代表通知栏消息。您在服务端推送通知栏消息时,如果通过服务端提供的开放接口设置了当应用进程在前台则不通过华为的统一消息中心(Notification Center,简称NC)展示消息,那么应用在前台时这个通知栏消息是直接透传给应用,由应用自己处理展示,此时RemoteMessage消息实体中包含RemoteMessage.Notification数据实例。Notification类中成员字段定义与下行消息中的AndroidNotification结构体字段定义相映射。如果应用进程在后台或者不存在,通知栏消息都是通过NC展示。

RemoteMessage.Builder类用于构建RemoteMessage消息实例。该类下所有方法从EMUI9.1版本开始生效。

Nested Class Summary

Qualifier and Type

Class Name and Description

public static class

RemoteMessage.Notification

RemoteMessage消息中的通知栏消息详情。

public static class

RemoteMessage.Builder

构建类,用于构建RemoteMessage消息实例。

Public Field Summary

Qualifier and Type

Field and Description

public static final int

PRIORITY_UNKNOWN

未知优先级。

public static final int

PRIORITY_HIGH

高优先级。

public static final int

PRIORITY_NORMAL

普通优先级。

Public Method Summary

Qualifier and Type

Method Name and Description

String

getCollapseKey()

获取消息的分类标识(折叠键)。

String

getData()

获取消息的有效内容数据。

String

getFrom()

获取消息的来源。

String

getTo()

获取消息的目的地。

String

getMessageId()

获取消息ID。

String

getMessageType()

获取消息的类型。

long

getSentTime()

获取消息从服务端下发的时间。

int

getTtl()

获取消息的最大缓存时间。

int

getOriginalUrgency()

获取应用设置的消息优先级。

int

getUrgency()

获取Push服务端设置的消息优先级。

RemoteMessage.Notification

getNotification()

从消息中获取通知数据实例。

Map<String, String>

getDataOfMap()

获取Map类型的消息内容数据。

String

getToken()

获取消息中的Token。

String

getAnalyticInfo()

获取批量任务消息标识bi_tag。

Map<String, String>

getAnalyticInfoMap()

获取Map类型的分析相关数据。

Public Fields

[h2]PRIORITY_UNKNOWN

Fields

public static final int PRIORITY_UNKNOWN

未知优先级。

另请参阅:Constant-values

[h2]PRIORITY_HIGH

Fields

public static final int PRIORITY_HIGH

高优先级。

另请参阅:Constant-values

[h2]PRIORITY_NORMAL

Fields

public static final int PRIORITY_NORMAL

普通优先级。

另请参阅:Constant-values

Public Methods

[h2]getCollapseKey

Method

public String getCollapseKey()

获取消息的分类标识(折叠键)。功能介绍请参见RemoteMessage.Builder中的setCollapseKey方法。

Returns

Type

Description

String

消息分类标识。

[h2]getData

Method

public String getData()

获取String类型的消息内容。

Returns

Type

Description

String

普通字符串或者JSON格式字符串,样例:"your data","{'param1':'value1', 'param2':'value2'}"。如果您同时调用了改变消息内容的方法(先调用了addData后调用了setData),setData方法会覆盖addData内容,调用本方法后会返回setData方法的内容。

[h2]getFrom

Method

public String getFrom()

获取消息的来源。您可以通过本方法获取Push服务端在下发消息时设置本消息归属的项目ID。

Returns

Type

Description

String

消息的来源。

[h2]getTo

Method

public String getTo()

获取消息的目的地。

Returns

Type

Description

String

消息目的地。

[h2]getMessageId

Method

public String getMessageId()

获取消息的ID。

Returns

Type

Description

String

消息的ID。

[h2]getMessageType

Method

public String getMessageType()

获取消息的类型,由您调用HmsMessaging中的send(RemoteMessage)发送上行消息时通过RemoteMessage.Builder中的setMessageType(String messageType)设置该字段值,SDK直接透传给您。透传消息与通知栏消息不下发该字段值,默认返回null。

Returns

Type

Description

String

您设置的消息类型。

[h2]getSentTime

Method

public long getSentTime()

获取消息从服务端下发的时间,单位:毫秒。

Returns

Type

Description

long

自1970年1月1日0时0分0秒起至消息从服务端下发的时间点的时间差,单位:毫秒。

[h2]getTtl

Method

public int getTtl()

获取消息的最大缓存时间,以秒为单位。如果是服务端下发的消息返回下行消息中的AndroidConfig中的ttl中设置的值,如果是上行消息则返回RemoteMessage.Builder中的setTtl()中设置的值。

Returns

Type

Description

int

消息的最大缓存时间,单位:秒。

[h2]getOriginalUrgency

Method

public int getOriginalUrgency()

获取应用设置的消息优先级,应用通过下行消息中的AndroidConfig中的urgency字段设置。

Returns

Type

Description

int

消息优先级,请参见Constant-values。

[h2]getUrgency

Method

public int getUrgency()

获取Push服务端设置的消息优先级。

Returns

Type

Description

int

消息优先级,请参见Constant-values。

[h2]getNotification

Method

public RemoteMessage.Notification getNotification()

如果服务端下发消息中设置了通知数据,应用调用此方法从消息中获取该通知数据。

Returns

Type

Description

RemoteMessage.Notification

通知栏消息实例。

[h2]getDataOfMap

Method

public Map<String, String> getDataOfMap()

获取Map类型消息内容。本方法不同于getData方法,本方法直接返回Map数据类型实例。

Returns

Type

Description

Map<String, String>

如果您发送消息中data字段设置为"123",则getData()方法返回"123",本方法返回空Map实例;data字段设置为"{'param1':'value1'}",则getData()方法返回JSON格式的字符串"{'param1':'value1'}",本方法返回一个包含{'param1':'value1'}的Map实例。

[h2]getToken

Method

public String getToken()

获取消息中的Token。

Returns

Type

Description

String

华为推送Token。

[h2]getAnalyticInfo

Method

public String getAnalyticInfo()

获取批量任务消息标识bi_tag。

Returns

Type

Description

String

普通字符串,样例:"your data"。

[h2]getAnalyticInfoMap

Method

public Map<String, String> getAnalyticInfoMap()

获取Map类型的分析相关数据。本方法不同于getAnalyticInfo方法,本方法直接返回Map数据类型实例。

Returns

Type

Description

Map<String, String>

如果您发送消息中bi_tag字段设置为"123",则getAnalyticInfo方法返回"123",本方法返回空Map实例;bi_tag字段设置为"{'param1':'value1'}",则getAnalyticInfo方法返回JSON格式的字符串"{'param1':'value1'}",本方法返回一个包含{'param1':'value1'}的Map实例。