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版本开始生效。 |
Qualifier and Type | Class Name and Description |
|---|---|
public static class | RemoteMessage消息中的通知栏消息详情。 |
public static class | 构建类,用于构建RemoteMessage消息实例。 |
Qualifier and Type | Field and Description |
|---|---|
public static final int | 未知优先级。 |
public static final int | 高优先级。 |
public static final int | 普通优先级。 |
Qualifier and Type | Method Name and Description |
|---|---|
String | 获取消息的分类标识(折叠键)。 |
String | getData() 获取消息的有效内容数据。 |
String | getFrom() 获取消息的来源。 |
String | getTo() 获取消息的目的地。 |
String | 获取消息ID。 |
String | 获取消息的类型。 |
long | 获取消息从服务端下发的时间。 |
int | getTtl() 获取消息的最大缓存时间。 |
int | 获取应用设置的消息优先级。 |
int | 获取Push服务端设置的消息优先级。 |
| 从消息中获取通知数据实例。 | |
Map<String, String> | 获取Map类型的消息内容数据。 |
String | getToken() 获取消息中的Token。 |
String | 获取批量任务消息标识bi_tag。 |
Map<String, String> | 获取Map类型的分析相关数据。 |
Method |
|---|
public String getCollapseKey() 获取消息的分类标识(折叠键)。功能介绍请参见RemoteMessage.Builder中的setCollapseKey方法。 |
Returns
Type | Description |
|---|---|
String | 消息分类标识。 |
Method |
|---|
public String getFrom() 获取消息的来源。您可以通过本方法获取Push服务端在下发消息时设置本消息归属的项目ID。 |
Returns
Type | Description |
|---|---|
String | 消息的来源。 |
Method |
|---|
public String getMessageId() 获取消息的ID。 |
Returns
Type | Description |
|---|---|
String | 消息的ID。 |
Method |
|---|
public String getMessageType() 获取消息的类型,由您调用HmsMessaging中的send(RemoteMessage)发送上行消息时通过RemoteMessage.Builder中的setMessageType(String messageType)设置该字段值,SDK直接透传给您。透传消息与通知栏消息不下发该字段值,默认返回null。 |
Returns
Type | Description |
|---|---|
String | 您设置的消息类型。 |
Method |
|---|
public long getSentTime() 获取消息从服务端下发的时间,单位:毫秒。 |
Returns
Type | Description |
|---|---|
long | 自1970年1月1日0时0分0秒起至消息从服务端下发的时间点的时间差,单位:毫秒。 |
Method |
|---|
public int getTtl() 获取消息的最大缓存时间,以秒为单位。如果是服务端下发的消息返回下行消息中的AndroidConfig中的ttl中设置的值,如果是上行消息则返回RemoteMessage.Builder中的setTtl()中设置的值。 |
Returns
Type | Description |
|---|---|
int | 消息的最大缓存时间,单位:秒。 |
Method |
|---|
public int getOriginalUrgency() 获取应用设置的消息优先级,应用通过下行消息中的AndroidConfig中的urgency字段设置。 |
Returns
Type | Description |
|---|---|
int | 消息优先级,请参见Constant-values。 |
Method |
|---|
public int getUrgency() 获取Push服务端设置的消息优先级。 |
Returns
Type | Description |
|---|---|
int | 消息优先级,请参见Constant-values。 |
Method |
|---|
public RemoteMessage.Notification getNotification() 如果服务端下发消息中设置了通知数据,应用调用此方法从消息中获取该通知数据。 |
Returns
Type | Description |
|---|---|
通知栏消息实例。 |
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实例。 |
Method |
|---|
public String getToken() 获取消息中的Token。 |
Returns
Type | Description |
|---|---|
String | 华为推送Token。 |
Method |
|---|
public String getAnalyticInfo() 获取批量任务消息标识bi_tag。 |
Returns
Type | Description |
|---|---|
String | 普通字符串,样例:"your data"。 |
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实例。 |