文档管理中心

此版本文档已归档不再维护,推荐您使用最新版本

API参考推送服务Android客户端API(已归档)com.huawei.hms.push(已归档)RemoteMessage(已归档)RemoteMessage.Notification(已归档)

RemoteMessage.Notification

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

Public Method Summary

Return typeMethod name
String

getTitle()

String

getTitleLocalizationKey() 

String[]

getTitleLocalizationArgs()

String

getBodyLocalizationKey()

String[]

getBodyLocalizationArgs()

String

getBody()

String

getIcon()

String

getSound()

String

getTag()

String

getColor()

String

getClickAction()

String

getChannelId()

Uri

getImageUrl()

Uri

getLink()

int

getNotifyId()

booleanisDefaultLight()
booleanisDefaultSound()
booleanisDefaultVibrate()
longgetWhen()
int[]getLightSettings()
IntegergetBadgeNumber()
booleanisAutoCancel()
IntegergetImportance()
StinggetTicker()
long[]getVibrateConfig()
intgetVisibility()
StringgetIntentUri()

Public Methods

Method
public String getTitle()
获取消息的标题。
Method
public String getTitleLocalizationKey()
通知消息本地化展示功能中获取消息标题本地化的关键字符串。要实现通知消息本地化功能,本字符串必须与应用的本地字符串资源strings.xml中的定义的节点名一致。
Method
public String[] getTitleLocalizationArgs()

获取通知消息标题本地化的可变字符串值,与getTitleLocalizationKey配套使用。通过getTitleLocalizationKey()获取的字符串key要与应用本地字符串资源strings.xml中的节点名一致,并且getTitleLocalizationArgs获取到的字符串数组长度必须大于等于strings.xml中的字符串key对应的值中占位符的个数。具体请参考开发指南通知消息本地化部分。

举例:

getTitleLocalizationKey: "demo_title_new"

getTitleLocalizationArgs: ["apple", "orange"]

strings.xml中配置

  1. <string name="demo_title_new">I want eat %1$s and %2$s.</string>
Method
public String getBodyLocalizationKey()
通知消息本地化展示功能中获取消息内容本地化的关键字符串。要实现通知消息本地化功能,本字符串必须与应用的本地字符串资源strings.xml中的定义的节点名一致。
Method
public String[] getBodyLocalizationArgs()
获取通知消息内容本地化的可变字符串值,与getBodyLocalizationKey配套使用。通过getBodyLocalizationKey()获取的字符串key要与应用本地字符串资源strings.xml中的节点名字符串一致,并且getBodyLocalizationArgs获取到的字符串数组长度必须大于等于strings.xml中的字符串key对应的值中占位符的个数。具体请参考开发指南通知消息本地化部分。
Method
public String getBody()
获取消息的展示内容。
Method
public String getIcon()
获取通知小图标的图像资源名称,所有图标文件都存放在Android设备上应用的/res/raw/**目录下。

Return

typedesc
String小图标资源文件名,例如"/raw/ic_launcher",对应本地的/res/raw/ic_launcher.png
Method
public String getSound()
获取通知显示时要播放的声音资源名称,所有声音文件都存放在Android设备上应用的/res/raw/**目录下。如果没有设置则为null。

Return

typedesc
String声音资源文件名,例如"/raw/shake",对应本地的/res/raw/shake.mp3
Method
public String getTag()
获取消息的tag,用于消息覆盖功能。消息如果设置为相同的tag,最终发送的那条消息覆盖之前的消息。

Return

typedesc
String消息的tag
Method
public String getColor()
获取消息的图标和按钮颜色,格式为#RRGGBB格式。

Return

typedesc
String消息中图标和按钮的颜色
Method
public String getClickAction()
获取通知消息中的action。如果未设置则返回null。定义可以参考服务端发送Push消息中ClickAction结构中action字段的定义。

Return

typedesc
String通知消息点击后拉起的应用页面,action必须是AndroidManifest.xml中定义的Activity的intent-filter标签中声明的action,否则会打开页面失败。
Method
public String getChannelId()
获取消息的自定义渠道号,指定消息要展示在哪个通知渠道上。如果没有设置则为null。

Return

typedesc
String自定义渠道号
Method
public Uri getImageUrl()
从消息中获取大图标URL,是一个公网能访问的图片URL。

Return

typedesc
Uri如果开发者设置了大图标URL返回该URL,否则返回null。
Method
public Uri getLink()
从消息中获取深度链接,即特定的URL,比如网页或者富媒体URL。如果没有设置则为null。
Method
public int getNotifyId()
获取每条消息的唯一标识。不同的消息可以有相同的notifyId,实现新的消息覆盖老的。

Return

typedesc
int消息的唯一标识
Method
public boolean isDefaultLight()
获取通知消息是否使用默认的通知灯设置。详细介绍请参见服务端发送Push消息中的结构体AndroidNotification关于关于use_default_light字段的说明。

Return

typedesc
boolean返回true或者false
Method
public boolean isDefaultSound()
获取通知消息是否使用默认声音。详细介绍请参见服务端发送Push消息中的结构体AndroidNotification关于default_sound字段的说明。

Return

typedesc
boolean返回true或者false
Method
public boolean isDefaultVibrate()
获取通知是否使用默认的震动模式。详细介绍请参见服务端发送Push消息中的结构体AndroidNotification关于use_default_vibrate字段的说明。

Return

typedesc
boolean返回true或者false
Method
public long getWhen()
从通知消息中获取事件发生的时间,单位ms。开发者自己展示通知消息时可以按此时间排序。
Method
public int[] getLightSettings()
获取呼吸灯的频率和颜色。详细介绍请参见服务端发送Push消息中的结构体AndroidNotification关于关于light_settings字段的说明。
Method
public Integer getBadgeNumber()
从通知消息获取设置的角标数字。
Method
public boolean isAutoCancel()
获取通知是否具有粘性。为true时,通知栏消息点击后会消失;为false,点击通知栏消息后,消息不会消失,可以右划删除消息,或者用小刷子删除。

Return

typedesc
boolean返回true或者false
Method
public Integer getImportance()
获取通知消息的优先级。
Method
public String getTicker()
获取通知消息在状态栏的内容提示文本。
Method
public long[] getVibrateConfig()
获取振动模式。详细介绍请参见服务端发送Push消息中的结构体AndroidNotification关于vibrate_config字段的说明。

Return

typedesc
int[]数组长度最大为10,每个元素的单位为ms。
Method
public int getVisibility()
获取通知的可见性级别。详细介绍参见结构体AndroidNotification关于visibility的定义说明。
Method
public String getIntentUri()
获取通知消息中的意图。意图可以是打开应用自定义的页面,定义可以参考服务端发送Push消息中ClickAction结构中intent字段的定义。
本页面可能包含由第三方许可的内容,请参考具体描述
在 API参考 中进行搜索
请输入您想要搜索的关键词