树叶云鸿蒙OS教程:鸿蒙OS NotificationSlot

NotificationSlot

java.lang.Object

|—ohos.event.notification.NotificationSlot

public final class NotificationSlot
extends Object
implements Sequenceable

定义了一个公共通知主题,它是一个包含通知音、振动、锁屏显示和级别的功能的集合。 您可以将这个类与一个应用程序关联起来,使应用程序发布的所有通知都具有通知主题的特性。

一个应用程序可以与一个或多个 NotificationSlot 实例相关联。

Since:

1

嵌套类摘要

从接口 ohos.utils.Sequenceable 继承的嵌套类/接口
Sequenceable.ProducerT

字段摘要

修饰符和类型字段描述
static intLEVEL_DEFAULT表示开启通知功能,状态栏显示通知图标,不带横幅,但有提示音。
static intLEVEL_HIGH表示开启通知功能,状态栏显示通知图标,带有横幅和提示音。
static intLEVEL_LOW表示通知功能开启,状态栏显示通知图标,无横幅或提示音。
static intLEVEL_MIN表示开启了通知功能,但状态栏中不显示通知图标,没有横幅或提示音。
static intLEVEL_NONE表示通知功能已关闭。
static intLEVEL_UNDEFINED表示用户未定义级别。
static Sequenceable.ProducerNotificationSlotPRODUCER从 Parcel 创建一个 NotificationSlot 实例。

构造函数摘要

构造函数描述
NotificationSlot(String id, String name, int level)用于初始化 NotificationSlot 对象的 ID、名称和级别的构造函数。

方法总结

修饰符和类型方法描述
booleancanEnableLight()获取NotificationSlot对象中是否开启通知灯,由setEnableLight(boolean)设置。
booleancanVibrate()获取 NotificationSlot 对象的振动状态,由 setEnableVibration(boolean) 设置。
voidenableBadge(boolean isShowBadge)设置收到通知后是否在主屏幕上显示应用程序图标标记(应用程序图标角落的数字或点)。
voidenableBypassDnd(boolean bypassDnd)设置是否绕过系统中的请勿打扰 (DND) 模式。
StringgetDescription()获取一个 NotificationSlot 对象的描述,由 setDescription(java.lang.String) 设置。
StringgetId()获取 NotificationSlot 对象的 ID。
intgetLedLightColor()获取 NotificationSlot 对象中通知灯的颜色,由 setLedLightColor(int) 设置。
intgetLevel()获取 NotificationSlot 对象的级别,由 setLevel(int) 设置。
intgetLockscreenVisibleness()获取一个NotificationSlot对象在锁屏上的通知显示效果,由setLockscreenVisibleness(int)设置。
StringgetName()获取 NotificationSlot 对象的名称。
StringgetSlotGroup()获取该NotificationSlot对象所属的NotificationSlotGroup对象的ID,由setSlotGroup(java.lang.String)设置。
UrigetSound()获取NotificationSlot对象的提示音,由setSound(ohos.utils.net.Uri)设置。
long[]getVibrationStyle()获取此 NotificationSlot 中通知的振动样式。
booleanisEnableBypassDnd()获取 NotificationSlot 对象是否绕过免打扰模式,由 enableBypassDnd(boolean) 设置。
booleanisShowBadge()获取 NotificationSlot 对象的应用程序图标徽章状态,该状态由 enableBadge(boolean) 设置。
booleanmarshalling(Parcel out)将 NotificationSlot 对象编组到 Parcel 中。
voidsetDescription(String description)设置 NotificationSlot 对象的描述。
voidsetEnableLight(boolean isLightEnabled)指定在设备上收到通知时是否启用通知灯,前提是此设备有通知灯。
voidsetEnableVibration(boolean vibration)设置是否在收到通知时启用振动。
voidsetLedLightColor(int color)将通知灯的颜色设置为在设备上接收到通知时闪烁,前提是此设备具有通知灯并且使用值 true 调用 setEnableLight(boolean)。
voidsetLevel(int level)设置 NotificationSlot 对象的级别。
voidsetLockscreenVisibleness(int visibleness)设置是否以及如何在锁定屏幕上显示通知。
voidsetName(String name)设置 NotificationSlot 对象的名称。
voidsetSlotGroup(String groupId)将 NotificationSlot 对象绑定到指定的 NotificationSlotGroup。
voidsetSound(Uri sound)为 NotificationSlot 对象设置提示音,在收到通知后播放。
voidsetVibrationStyle(long[] vibrationValues)设置此 NotificationSlot 中通知的振动样式。
StringtoString()返回对象的字符串表示形式。
booleanunmarshalling(Parcel in)从 Parcel 中解组 NotificationSlot 对象。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口 ohos.utils.Sequenceable 继承的方法
hasFileDescriptor

字段详细信息

LEVEL_DEFAULT

public static final int LEVEL_DEFAULT

表示开启通知功能,状态栏显示通知图标,不带横幅,但有提示音。

Since:

1

LEVEL_HIGH

public static final int LEVEL_HIGH

表示开启通知功能,状态栏显示通知图标,带有横幅和提示音。

Since:

1

LEVEL_LOW

public static final int LEVEL_LOW

表示通知功能开启,状态栏显示通知图标,无横幅或提示音。

Since:

1

LEVEL_MIN

public static final int LEVEL_MIN

表示开启了通知功能,但状态栏中不显示通知图标,没有横幅或提示音。

Since:

1

LEVEL_NONE

public static final int LEVEL_NONE

表示通知功能已关闭。

Since:

1

LEVEL_UNDEFINED

public static final int LEVEL_UNDEFINED

表示用户未定义级别。

这是一个保留的常量。 不要将其与任何通知相关联。

Since:

3

PRODUCER

public static final Sequenceable.ProducerNotificationSlot PRODUCER

从 Parcel 创建一个 NotificationSlot 实例。

Since:

4

构造函数详细信息

NotificationSlot

public NotificationSlot(String id, String name, int level)

用于初始化 NotificationSlot 对象的 ID、名称和级别的构造函数。

参数:

参数名称参数描述
id指定 NotificationSlot 对象的 ID。 ID 必须是唯一的,并且它的长度不能超过 1000 个字符(超出的部分会被自动截断)。
name指定 NotificationSlot 对象的名称。 名称必须对用户可见,且长度不得超过 1000 个字符(超出部分会自动截断)。
level指定 NotificationSlot 对象的级别,决定通知的显示效果。 该值可以是 LEVEL_NONE、LEVEL_MIN、LEVEL_LOW、LEVEL_DEFAULT 或 LEVEL_HIGH。

Since:

1

方法详情

setLevel

public void setLevel(int level)

设置 NotificationSlot 对象的级别。

必须在调用 NotificationHelper#addNotificationSlot(NotificationSlot) 方法之前设置 setLevel(int level)。 否则,设置将不会生效。

参数:

参数名称参数描述
level指定 NotificationSlot 对象的级别,决定通知的显示效果。 该值可以是 LEVEL_NONE、LEVEL_MIN、LEVEL_LOW、LEVEL_DEFAULT 或 LEVEL_HIGH。

Since:

1

setName

public void setName(String name)

设置 NotificationSlot 对象的名称。

无论是否通过 NotificationHelper#addNotificationSlot(NotificationSlot) 创建了 NotificationSlot 对象,setName(String) 的设置都有效。

参数:

参数名称参数描述
name指定 NotificationSlot 对象的名称。 名称对用户可见,长度不得超过 1000 个字符(超出部分自动截断)。

Since:

1

setDescription

public void setDescription(String description)

设置 NotificationSlot 对象的描述。

无论是否通过 NotificationHelper#addNotificationSlot(NotificationSlot) 创建了 NotificationSlot 对象,setDescription(String) 的设置都有效。

参数:

参数名称参数描述
description描述 NotificationSlot 对象。 描述对用户可见,其长度不得超过 1000 个字符(超出部分将自动截断)。

Since:

1

enableBadge

public void enableBadge(boolean isShowBadge)

设置收到通知后是否在主屏幕上显示应用程序图标标记(应用程序图标角落的数字或点)。

enableBadge(boolean) 必须在调用 NotificationHelper#addNotificationSlot(NotificationSlot) 方法之前设置。 否则,设置将不会生效。

参数:

参数名称参数描述
isShowBadge指定是否显示应用程序图标标志。 如果该值为 true,则启用应用程序图标徽章; 如果值为 false,则禁用应用程序图标徽章。

Since:

1

enableBypassDnd

public void enableBypassDnd(boolean bypassDnd)

设置是否绕过系统中的请勿打扰 (DND) 模式。

enableBypassDnd(boolean)的设置只有在系统通知设置中为应用程序开启允许中断功能时才会生效。

参数:

参数名称参数描述
bypassDnd指定是否绕过应用程序的 DND 模式。 如果该值为 true,则绕过免打扰模式; 如果该值为 false,则不绕过 DND 模式。

Since:

1

setEnableVibration

public void setEnableVibration(boolean vibration)

设置是否在收到通知时启用振动。

必须在调用 NotificationHelper#addNotificationSlot(NotificationSlot) 方法之前设置 setEnableVibration(boolean)。 否则,设置将不会生效。

参数:

参数名称参数描述
vibration指示是否在收到通知时启用振动。 如果该值为true,则启用振动; 如果值为 false,则禁用振动。

Since:

1

setLockscreenVisibleness

public void setLockscreenVisibleness(int visibleness)

设置是否以及如何在锁定屏幕上显示通知。

此方法指定在锁定屏幕上显示通知的不同效果,以保护用户隐私。

该设置仅在系统通知设置中为应用程序开启锁屏通知功能时生效。

参数:

参数名称参数描述
visibleness指定锁屏上的通知显示效果,可以设置为 NotificationRequest#VISIBLENESS_TYPE_PUBLIC、NotificationRequest#VISIBLENESS_TYPE_PRIVATE 或 NotificationRequest#VISIBLENESS_TYPE_SECRET。

Since:

1

setSound

public void setSound(Uri sound)

为 NotificationSlot 对象设置提示音,在收到通知后播放。

必须在调用 NotificationHelper#addNotificationSlot(NotificationSlot) 方法之前设置 setSound(Uri)。 否则,设置将不会生效。

参数:

参数名称参数描述
sound指定提示音的路径。

Since:

1

setEnableLight

public void setEnableLight(boolean isLightEnabled)

指定在设备上收到通知时是否启用通知灯,前提是此设备有通知灯。

必须在调用 NotificationHelper#addNotificationSlot(NotificationSlot) 方法之前设置 setEnableLight(boolean)。 否则,设置将不会生效。

参数:

参数名称参数描述
isLightEnabled指定是否启用脉搏通知灯。 true 表示开启通知灯,false 表示不开启。

Since:

1

setLedLightColor

public void setLedLightColor(int color)

将通知灯的颜色设置为在设备上接收到通知时闪烁,前提是此设备具有通知灯并且使用值 true 调用 setEnableLight(boolean)。

必须在调用 NotificationHelper#addNotificationSlot(NotificationSlot) 方法之前设置 setLedLightColor(int)。 否则,设置将不会生效。

参数:

参数名称参数描述
color指示通知灯的颜色。

Since:

1

setSlotGroup

public void setSlotGroup(String groupId)

将 NotificationSlot 对象绑定到指定的 NotificationSlotGroup。

必须在调用 NotificationHelper#addNotificationSlot(NotificationSlot) 方法之前调用 setSlotGroup(String)。 否则,此方法不会生效。

参数:

参数名称参数描述
groupId表示要绑定的 NotificationSlotGroup 对象的 ID,必须是通过调用 NotificationHelper#addNotificationSlotGroup(NotificationSlotGroup) 创建的。

Since:

3

getId

public String getId()

获取 NotificationSlot 对象的 ID。

返回:

返回 NotificationSlot 对象的 ID,由 NotificationSlot(java.lang.String,java.lang.String,int) 设置。

Since:

1

getName

public String getName()

获取 NotificationSlot 对象的名称。

返回:

返回由 setName(java.lang.String) 设置的 NotificationSlot 对象的名称。

Since:

1

getDescription

public String getDescription()

获取一个 NotificationSlot 对象的描述,由 setDescription(java.lang.String) 设置。

返回:

返回 NotificationSlot 对象的描述。

Since:

1

getLevel

public int getLevel()

获取 NotificationSlot 对象的级别,由 setLevel(int) 设置。

返回:

返回 NotificationSlot 对象的级别。

Since:

1

isShowBadge

public boolean isShowBadge()

获取 NotificationSlot 对象的应用程序图标徽章状态,该状态由 enableBadge(boolean) 设置。

返回:

如果启用了应用程序图标徽章,则返回 true; 否则返回 false。

Since:

1

isEnableBypassDnd

public boolean isEnableBypassDnd()

获取 NotificationSlot 对象是否绕过免打扰模式,由 enableBypassDnd(boolean) 设置。

返回:

如果绕过 DND 模式,则返回 true; 否则返回 false。

Since:

1

canVibrate

public boolean canVibrate()

获取 NotificationSlot 对象的振动状态,由 setEnableVibration(boolean) 设置。

返回:

如果启用了振动,则返回 true; 否则返回 false。

Since:

1

getLockscreenVisibleness

public int getLockscreenVisibleness()

获取一个NotificationSlot对象在锁屏上的通知显示效果,由setLockscreenVisibleness(int)设置。

返回:

返回 NotificationSlot 对象在锁屏上的通知显示效果。

Since:

1

getSound

public Uri getSound()

获取NotificationSlot对象的提示音,由setSound(ohos.utils.net.Uri)设置。

返回:

返回 NotificationSlot 对象的提示音。

Since:

1

canEnableLight

public boolean canEnableLight()

获取NotificationSlot对象中是否开启通知灯,由setEnableLight(boolean)设置。

返回:

如果启用通知灯,则返回 true; 否则返回 false。

Since:

1

getLedLightColor

public int getLedLightColor()

获取 NotificationSlot 对象中通知灯的颜色,由 setLedLightColor(int) 设置。

返回:

返回通知灯的颜色。

Since:

1

getSlotGroup

public String getSlotGroup()

获取该NotificationSlot对象所属的NotificationSlotGroup对象的ID,由setSlotGroup(java.lang.String)设置。

返回:

返回此 NotificationSlot 对象所属的 NotificationSlotGroup 的 ID。

Since:

3

setVibrationStyle

public void setVibrationStyle(long[] vibrationValues)

设置此 NotificationSlot 中通知的振动样式。

如果将空数组或 null 传递给此方法,则系统将调用 setEnableVibration(boolean) 并将输入参数设置为 false。 如果将有效值传递给此方法,则系统调用 setEnableVibration(boolean) 并将输入参数设置为 true。 该方法仅在调用 NotificationHelper#addNotificationSlot(NotificationSlot) 之前生效。

参数:

参数名称参数描述
vibrationValues指示要设置的振动样式。

Since:

4

getVibrationStyle

public long[] getVibrationStyle()

获取此 NotificationSlot 中通知的振动样式。

返回:

返回此 NotificationSlot 的振动样式。

Since:

4

marshalling

public boolean marshalling(Parcel out)

将 NotificationSlot 对象编组到 Parcel 中。

进程可以调用 unmarshalling(ohos.utils.Parcel) 方法从 Parcel 中解组 NotificationSlot 对象以实现进程间通信 (IPC)。

指定者:

接口 Sequenceable 中的编组

参数:

参数名称参数描述
out指示用于编组的 Parcel 对象。

返回:

如果编组成功,则返回 true; 否则返回 false。

Since:

1

unmarshalling

public boolean unmarshalling(Parcel in)

从 Parcel 中解组 NotificationSlot 对象。

指定者:

在接口 Sequenceable 中解组

参数:

参数名称参数描述
in指示用于解组的 Parcel 对象。

返回:

如果解组成功,则返回 true; 否则返回 false。

Since:

1

toString

public String toString()

从类复制的描述:对象

返回对象的字符串表示形式。 通常,toString 方法返回一个“以文本方式表示”该对象的字符串。 结果应该是一个简洁但信息丰富的表示,易于人们阅读。 建议所有子类重写此方法。

Object 类的 toString 方法返回一个字符串,该字符串由对象作为其实例的类的名称、at 符号字符“@”和对象哈希码的无符号十六进制表示形式组成。 换句话说,此方法返回一个等于以下值的字符串:

 getClass().getName() + '@' + Integer.toHexString(hashCode()) 

覆盖:

类 Object 中的 toString

返回:

对象的字符串表示形式。

Since:

4

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/160095.html<

(0)
运维的头像运维
上一篇2025-03-17 14:47
下一篇 2025-03-17 14:48

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注