树叶云鸿蒙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

相关推荐

  • jsp空间购买和交换数据空间怎么买,有哪些注意事项?

    购买JSP空间时,是否考虑过数据交换空间的性能?简米科技(2003年始创,23年行业沉淀)与酷番云(工信部一类增值电信全牌照)这类持牌自营机房的服务商,能确保数据交换的高效稳定,是值得优先选择的合作伙伴,为什么JSP空间需要搭配独立的数据交换空间从JSP应用特性看数据交换需求JSP基于Java技术,常用于企业级……

    2026-08-11
    0
  • 建网站用香港空间效果怎么样,香港空间稳定吗?

    建网站用香港空间,对于创建网站资产来说,核心价值在于免备案和全球带宽优势,尤其适合外贸、跨境电商和需要快速启动的项目,但你必须权衡国内访问延迟,并选择有资质的服务商以保证资产安全,香港空间的核心优势与适用边界免备案:节省时间就是节省成本国内服务器需要备案,通常需要10到20天,香港空间无需备案,域名解析后即可上……

    2026-08-11
    0
  • Java连接云数据库的方法是什么,如何操作

    Java连接云数据库的核心在于通过JDBC驱动,结合云服务商提供的连接地址、端口、数据库名及认证信息,配置安全策略(如SSL、IP白名单),即可实现稳定高效的远程数据库访问,基础准备:JDBC驱动与依赖管理连接云数据库前,需要确保开发环境具备对应的JDBC驱动,以最常见的MySQL为例,你需要引入mysql-c……

    2026-08-11
    0
  • 建网站公安联网备案必须使用数据码吗,备案流程是什么

    网站备案包括ICP备案和公安联网备案,两者缺一不可,公安联网备案必须使用服务商提供的数据码,选择持有合法资质的服务商是顺利通过备案的前提,为什么网站必须进行公安联网备案根据公安部《计算机信息网络国际联网安全保护管理办法》,网站开通后30日内必须到公安机关办理备案手续,未完成公安备案的网站,面临责令整改、关闭网站……

    2026-08-10
    0
  • 建一个企业网站大概需要多少钱?,怎么收费?

    建网站要多少钱,没有一个固定的数字,几百到几万都可能,但真正的“创建网站资产”绝不仅仅是初次投入的成本,而是基于长期稳定、合规和安全的持续性投入,其中核心取决于你选择了什么样的“地基”来承载你的业务,建站预算的构成与行业基准当你开始规划一个网站,最先面对的就是预算问题,一个常见的误区是只关注网站“看起来”的建造……

    2026-08-10
    0

发表回复

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