Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
a8b830b1
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a8b830b1
编写于
5月 19, 2023
作者:
X
xuzhihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Bugfix: 修复事件通知资料问题
Signed-off-by:
N
xuzhihao
<
xuzhihao16@huawei.com
>
上级
0d6e6b76
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
261 addition
and
359 deletion
+261
-359
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
+8
-8
zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md
...lication-dev/reference/apis/js-apis-commonEventManager.md
+84
-0
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationSubscriber.md
...apis/js-apis-inner-notification-notificationSubscriber.md
+6
-0
zh-cn/application-dev/reference/apis/js-apis-notification.md
zh-cn/application-dev/reference/apis/js-apis-notification.md
+39
-344
zh-cn/application-dev/reference/apis/js-apis-notificationManager.md
...ication-dev/reference/apis/js-apis-notificationManager.md
+112
-4
zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md
...ation-dev/reference/apis/js-apis-notificationSubscribe.md
+12
-3
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
浏览文件 @
a8b830b1
...
...
@@ -32,7 +32,7 @@ publish(event: string, callback: AsyncCallback\<void>): void
**参数:**
|
名称
| 类型 | 必填 | 说明 |
|
参数名
| 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------- |
| event | string | 是 | 表示要发送的公共事件。 |
| callback | AsyncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
...
...
@@ -66,7 +66,7 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
**参数:**
|
名称
| 类型 | 必填 | 说明 |
|
参数名
| 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | 是 | 表示要发布的公共事件。 |
| options |
[
CommonEventPublishData
](
./js-apis-inner-commonEvent-commonEventPublishData.md
)
| 是 | 表示发布公共事件的属性。 |
...
...
@@ -111,7 +111,7 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo
**参数:**
|
名称
| 类型 | 必填 | 说明 |
|
参数名
| 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------------------- |
| event | string | 是 | 表示要发送的公共事件。 |
| userId | number | 是 | 表示指定向该用户ID发送此公共事件。 |
...
...
@@ -151,7 +151,7 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
**参数:**
|
名称
| 类型 | 必填 | 说明 |
|
参数名
| 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | 是 | 表示要发布的公共事件。 |
| userId | number | 是 | 表示指定向该用户ID发送此公共事件。 |
...
...
@@ -197,7 +197,7 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
**参数:**
|
名称
| 类型 | 必填 | 说明 |
|
参数名
| 类型 | 必填 | 说明 |
| ------------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
./js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
| 是 | 表示订阅信息。 |
| callback | AsyncCallback
\<
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
> | 是 | 表示创建订阅者的回调方法。 |
...
...
@@ -240,7 +240,7 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise<CommonEventSu
**参数:**
|
名称
| 类型 | 必填 | 说明 |
|
参数名
| 类型 | 必填 | 说明 |
| ------------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
./js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
| 是 | 表示订阅信息。 |
...
...
@@ -281,7 +281,7 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback<CommonEvent
**参数:**
|
名称
| 类型 | 必填 | 说明 |
|
参数名
| 类型 | 必填 | 说明 |
| ---------- | ---------------------------------------------------- | ---- | -------------------------------- |
| subscriber |
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
| 是 | 表示订阅者对象。 |
| callback | AsyncCallback
\<
[
CommonEventData
](
./js-apis-inner-commonEvent-commonEventData.md
)
> | 是 | 表示接收公共事件数据的回调函数。 |
...
...
@@ -334,7 +334,7 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
**参数:**
|
名称
| 类型 | 必填 | 说明 |
|
参数名
| 类型 | 必填 | 说明 |
| ---------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber |
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
| 是 | 表示订阅者对象。 |
| callback | AsyncCallback
\<
void> | 否 | 表示取消订阅的回调方法。 |
...
...
zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md
浏览文件 @
a8b830b1
...
...
@@ -547,3 +547,87 @@ CommonEventManager.removeStickyCommonEvent("sticky_event").then(() => {
});
```
## CommonEventManager.setStaticSubscriberState<sup>10+</sup>
setStaticSubscriberState(enable: boolean, callback: AsyncCallback
\<
void>): void;
方法介绍:为当前应用设置静态订阅事件使能或去使能状态。使用callback异步回调。
**系统能力:**
SystemCapability.Notification.CommonEvent
**系统API**
:此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------- |
| enable | boolean | 是 | 表示静态订阅事件使能状态。 true:使能 false:去使能。 |
| callback | AsyncCallback
<void>
| 是 | 表示设置静态订阅事件使能状态的回调方法。 |
**错误码:**
错误码介绍请参考
[
@ohos.commonEventManager(事件)
](
../errorcodes/errorcode-CommonEventService.md
)
| 错误码ID | 错误信息 |
| -------- | ----------------------------------- |
| 1500007 | error sending message to Common Event Service. |
| 1500008 | Common Event Service does not complete initialization. |
**示例:**
```
ts
CommonEventManager
.
setStaticSubscriberState
(
true
,
(
err
)
=>
{
if
(
!
err
)
{
console
.
info
(
`Set static subscriber state callback failed, err is null.`
);
return
;
}
if
(
err
.
code
)
{
console
.
info
(
`Set static subscriber state callback failed, errCode:
${
err
.
code
}
, errMes:
${
err
.
message
}
`
);
return
;
}
console
.
info
(
`Set static subscriber state callback success`
);
});
```
## CommonEventManager.setStaticSubscriberState<sup>10+</sup>
setStaticSubscriberState(enable: boolean): Promise
\<
void>;
方法介绍:为当前应用设置静态订阅事件使能或去使能状态。使用Promise异步回调。
**系统能力:**
SystemCapability.Notification.CommonEvent
**系统API**
:此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------- |
| enable | boolean | 是 | 表示静态订阅事件使能状态。 true:使能 false:去使能。 |
**返回值:**
| 类型 | 说明 |
| -------------- | ---------------------------- |
| Promise
\<
void> | 表示设置静态订阅事件使能状态的对象。 |
**错误码:**
错误码介绍请参考
[
@ohos.commonEventManager(事件)
](
../errorcodes/errorcode-CommonEventService.md
)
| 错误码ID | 错误信息 |
| -------- | ----------------------------------- |
| 1500007 | error sending message to Common Event Service. |
| 1500008 | Common Event Service does not complete initialization. |
**示例:**
```
ts
CommonEventManager
.
setStaticSubscriberState
(
false
).
then
(()
=>
{
console
.
info
(
`Set static subscriber state promise success`
);
}).
catch
((
err
)
=>
{
console
.
info
(
`Set static subscriber state promise failed, errCode:
${
err
.
code
}
, errMes:
${
err
.
message
}
`
);
});
```
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationSubscriber.md
浏览文件 @
a8b830b1
...
...
@@ -6,6 +6,12 @@
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
js
import
notificationSubscribe
from
'
@ohos.notificationSubscribe
'
;
```
**系统API**
:此接口为系统接口,三方应用不支持调用。
### onConsume
...
...
zh-cn/application-dev/reference/apis/js-apis-notification.md
浏览文件 @
a8b830b1
...
...
@@ -726,7 +726,7 @@ subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, c
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------- | ---- | ---------------- |
| subscriber |
[
NotificationSubscriber
](
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| subscriber |
[
NotificationSubscriber
](
js-apis-inner-notification-notificationSubscriber.md
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| info |
[
NotificationSubscribeInfo
](
#notificationsubscribeinfo
)
| 是 | 通知订阅信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 订阅动作回调函数。 |
...
...
@@ -769,7 +769,7 @@ subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>):
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ---------------------- | ---- | ---------------- |
| subscriber |
[
NotificationSubscriber
](
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| subscriber |
[
NotificationSubscriber
](
js-apis-inner-notification-notificationSubscriber.md
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 订阅动作回调函数。 |
**示例:**
...
...
@@ -807,7 +807,7 @@ subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo):
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------- | ---- | ------------ |
| subscriber |
[
NotificationSubscriber
](
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| subscriber |
[
NotificationSubscriber
](
js-apis-inner-notification-notificationSubscriber.md
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| info |
[
NotificationSubscribeInfo
](
#notificationsubscribeinfo
)
| 否 | 通知订阅信息。 |
**示例:**
...
...
@@ -840,7 +840,7 @@ unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>)
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ---------------------- | ---- | -------------------- |
| subscriber |
[
NotificationSubscriber
](
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| subscriber |
[
NotificationSubscriber
](
js-apis-inner-notification-notificationSubscriber.md
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 取消订阅动作回调函数。 |
**示例:**
...
...
@@ -878,7 +878,7 @@ unsubscribe(subscriber: NotificationSubscriber): Promise\<void\>
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ---------------------- | ---- | ------------ |
| subscriber |
[
NotificationSubscriber
](
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
| subscriber |
[
NotificationSubscriber
](
js-apis-inner-notification-notificationSubscriber.md
#notificationsubscriber
)
| 是 | 通知订阅对象。 |
**示例:**
...
...
@@ -1459,7 +1459,7 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | ----------------------------------| ---- | -------------------- |
| bundle |
[
BundleOption
](
#bundleoption
)
| 是 | 指定应用的包信息。 |
| notificationKey |
[
NotificationKey
](
#notificationkey
)
| 是 | 通知键值。 |
| notificationKey |
[
NotificationKey
](
#notificationkey
deprecated
)
| 是 | 通知键值。 |
| reason |
[
RemoveReason
](
#removereason9
)
| 是 | 通知删除原因。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 删除指定通知回调函数。 |
...
...
@@ -1501,7 +1501,7 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | --------------- | ---- | ---------- |
| bundle |
[
BundleOption
](
#bundleoption
)
| 是 | 指定应用的包信息。 |
| notificationKey |
[
NotificationKey
](
#notificationkey
)
| 是 | 通知键值。 |
| notificationKey |
[
NotificationKey
](
#notificationkey
deprecated
)
| 是 | 通知键值。 |
| reason |
[
RemoveReason
](
#removereason9
)
| 是 | 通知删除原因。 |
**示例:**
...
...
@@ -1536,7 +1536,7 @@ remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>):
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------- | ---- | -------------------- |
| hashCode | string | 是 | 通知唯一ID。可以通过
[
onConsume
](
#onconsume
)
回调的入参
[
SubscribeCallbackData
](
#subscribecallbackdata
)
获取其内部
[
NotificationRequest
](
#notificationrequest
)
对象中的hashCode。 |
| hashCode | string | 是 | 通知唯一ID。可以通过
[
onConsume
](
js-apis-inner-notification-notificationSubscriber.md
#onconsume
)
回调的入参
[
SubscribeCallbackData
](
#subscribecallbackdata
)
获取其内部
[
NotificationRequest
](
#notificationrequest
)
对象中的hashCode。 |
| reason |
[
RemoveReason
](
#removereason9
)
| 是 | 通知删除原因。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 删除指定通知回调函数。 |
...
...
@@ -2777,332 +2777,6 @@ Notification.getDeviceRemindType().then((data) => {
});
```
## NotificationSubscriber
作为订阅通知接口
[
subscribe
](
#notificationsubscribe
)
的入参,提供订阅者接收到新通知、取消通知等的回调方法。
**系统API**
:此接口为系统接口,三方应用不支持调用。
### onConsume
onConsume?: (data:
[
SubscribeCallbackData
](
#subscribecallbackdata
)
) => void
接收到新通知的回调函数。
**系统能力**
:SystemCapability.Notification.Notification
**系统接口**
: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data |
[
SubscribeCallbackData
](
#subscribecallbackdata
)
| 是 | 新接收到的通知信息。 |
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
subscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onConsumeCallback
(
data
)
{
let
req
=
data
.
request
;
console
.
info
(
'
===> onConsume callback req.id:
'
+
req
.
id
);
};
let
subscriber
=
{
onConsume
:
onConsumeCallback
};
Notification
.
subscribe
(
subscriber
,
subscribeCallback
);
```
### onCancel
onCancel?:(data:
[
SubscribeCallbackData
](
#subscribecallbackdata
)
) => void
取消通知的回调函数。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data |
[
SubscribeCallbackData
](
#subscribecallbackdata
)
| 是 | 需要取消的通知信息。 |
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
subscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onCancelCallback
(
data
)
{
let
req
=
data
.
request
;
console
.
info
(
'
===> onCancel callback req.id:
'
+
req
.
id
);
}
let
subscriber
=
{
onCancel
:
onCancelCallback
};
Notification
.
subscribe
(
subscriber
,
subscribeCallback
);
```
### onUpdate
onUpdate?:(data:
[
NotificationSortingMap
](
#notificationsortingmap
)
) => void
更新通知排序的回调函数。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data |
[
NotificationSortingMap
](
#notificationsortingmap
)
| 是 | 最新的通知排序列表。 |
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
subscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onUpdateCallback
(
map
)
{
console
.
info
(
'
===> onUpdateCallback map:
'
+
JSON
.
stringify
(
map
));
}
let
subscriber
=
{
onUpdate
:
onUpdateCallback
};
Notification
.
subscribe
(
subscriber
,
subscribeCallback
);
```
### onConnect
onConnect?:() => void
订阅完成的回调函数。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
subscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onConnectCallback
()
{
console
.
info
(
'
===> onConnect in test
'
);
}
let
subscriber
=
{
onConnect
:
onConnectCallback
};
Notification
.
subscribe
(
subscriber
,
subscribeCallback
);
```
### onDisconnect
onDisconnect?:() => void
取消订阅的回调函数。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
subscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
unsubscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
unsubscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
unsubscribeCallback
"
);
}
};
function
onConnectCallback
()
{
console
.
info
(
'
===> onConnect in test
'
);
}
function
onDisconnectCallback
()
{
console
.
info
(
'
===> onDisconnect in test
'
);
}
let
subscriber
=
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
};
// 订阅通知后会收到onConnect回调
Notification
.
subscribe
(
subscriber
,
subscribeCallback
);
// 取消订阅后会收到onDisconnect回调
Notification
.
unsubscribe
(
subscriber
,
unsubscribeCallback
);
```
### onDestroy
onDestroy?:() => void
服务失联回调函数。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
subscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onDestroyCallback
()
{
console
.
info
(
'
===> onDestroy in test
'
);
}
let
subscriber
=
{
onDestroy
:
onDestroyCallback
};
Notification
.
subscribe
(
subscriber
,
subscribeCallback
);
```
### onDoNotDisturbDateChange<sup>8+</sup>
onDoNotDisturbDateChange?:(mode: notification.
[
DoNotDisturbDate
](
#donotdisturbdate8
)
) => void
免打扰时间选项发生变更时的回调函数。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| mode | notification.
[
DoNotDisturbDate
](
#donotdisturbdate8
)
| 是 | 回调返回免打扰时间选项变更。 |
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
subscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onDoNotDisturbDateChangeCallback
(
mode
)
{
console
.
info
(
'
===> onDoNotDisturbDateChange:
'
+
mode
);
}
let
subscriber
=
{
onDoNotDisturbDateChange
:
onDoNotDisturbDateChangeCallback
};
Notification
.
subscribe
(
subscriber
,
subscribeCallback
);
let
doNotDisturbDate
=
{
type
:
Notification
.
DoNotDisturbType
.
TYPE_ONCE
,
begin
:
new
Date
(),
end
:
new
Date
(
2021
,
11
,
15
,
18
,
0
)
}
// 设置一个新的免打扰时间选项时触发onDoNotDisturbDateChange回调
Notification
.
setDoNotDisturbDate
(
doNotDisturbDate
).
then
(()
=>
{
console
.
info
(
"
setDoNotDisturbDate sucess
"
);
});
```
### onEnabledNotificationChanged<sup>8+</sup>
onEnabledNotificationChanged?:(callbackData:
[
EnabledNotificationCallbackData
](
#enablednotificationcallbackdata8
)
) => void
监听应用通知使能变化。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback
\<
[
EnabledNotificationCallbackData
](
#enablednotificationcallbackdata8
)
\>
| 是 | 回调返回监听到的应用信息。 |
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
info
(
"
subscribe failed
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onEnabledNotificationChangedCallback
(
callbackData
)
{
console
.
info
(
"
bundle:
"
+
callbackData
.
bundle
);
console
.
info
(
"
uid:
"
+
callbackData
.
uid
);
console
.
info
(
"
enable:
"
+
callbackData
.
enable
);
};
let
subscriber
=
{
onEnabledNotificationChanged
:
onEnabledNotificationChangedCallback
};
Notification
.
subscribe
(
subscriber
,
subscribeCallback
);
let
bundle
=
{
bundle
:
"
bundleName1
"
,
}
// 设置指定应用通知使能状态触发onEnabledNotificationChanged回调
Notification
.
enableNotification
(
bundle
,
false
).
then
(()
=>
{
console
.
info
(
"
enableNotification sucess
"
);
});
```
## SubscribeCallbackData
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Notification.Notification
...
...
@@ -3131,10 +2805,13 @@ Notification.enableNotification(bundle, false).then(() => {
| enable | boolean | 是 | 否 | 应用通知使能状态。 |
## DoNotDisturbDate<sup>8+</sup>
## DoNotDisturbDate<sup>8+</sup>
<sup>deprecated</sup>
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Notification.Notification
> **说明:**
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[notificationManager.DoNotDisturbDate](js-apis-notificationManager.md#donotdisturbdate)替代
**系统API**
:此接口为系统接口,三方应用不支持调用。
| 名称 | 类型 | 可读 | 可写 | 说明 |
...
...
@@ -3143,10 +2820,13 @@ Notification.enableNotification(bundle, false).then(() => {
| begin | Date | 是 | 是 | 免打扰设置的起点时间。 |
| end | Date | 是 | 是 | 免打扰设置的终点时间。 |
## DoNotDisturbType<sup>8+</sup>
## DoNotDisturbType<sup>8+</sup>
<sup>deprecated</sup>
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Notification.Notification
> **说明:**
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[notificationManager.DoNotDisturbType](js-apis-notificationManager.md#donotdisturbtype)替代
**系统API**
: 此接口为系统接口,三方应用不支持调用。
| 名称 | 值 | 说明 |
...
...
@@ -3182,19 +2862,25 @@ Notification.enableNotification(bundle, false).then(() => {
| LEVEL_HIGH | 4 | 表示通知功能已启用,状态栏中显示通知图标,有横幅和提示音。 |
## BundleOption
## BundleOption
<sup>deprecated</sup>
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 类型 | 可读 | 可写 | 说明 |
> **说明:**
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[notificationManager.BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)替代
| 名称 | 类型 | 只读 | 必填 | 说明 |
| ------ | ------ |---- | --- | ------ |
| bundle | string |
是
| 是 | 应用的包信息。 |
| uid | number |
是 | 是
| 用户ID。 |
| bundle | string |
否
| 是 | 应用的包信息。 |
| uid | number |
否 | 否
| 用户ID。 |
## NotificationKey
## NotificationKey
<sup>deprecated</sup>
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Notification.Notification
> **说明:**
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[notificationManager.NotificationKey](js-apis-notificationSubscribe.md#notificationkey)替代
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----- | ------ | ---- | --- | -------- |
| id | number | 是 | 是 | 通知ID。 |
...
...
@@ -3479,12 +3165,15 @@ Notification.enableNotification(bundle, false).then(() => {
| inputKey | string | 是 | 是 | 用户输入时用于标识此输入的key。 |
## DeviceRemindType<sup>8+</sup>
## DeviceRemindType<sup>8+</sup>
<sup>deprecated</sup>
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
> **说明:**
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[notificationManager.DeviceRemindType](js-apis-notificationManager.md#deviceremindtype)替代
| 名称 | 值 | 说明 |
| -------------------- | --- | --------------------------------- |
| IDLE_DONOT_REMIND | 0 | 设备未被使用,无需提醒。 |
...
...
@@ -3493,24 +3182,30 @@ Notification.enableNotification(bundle, false).then(() => {
| ACTIVE_REMIND | 3 | 提醒设备正在使用。 |
## SourceType<sup>8+</sup>
## SourceType<sup>8+</sup>
<sup>deprecated</sup>
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
> **说明:**
> 从 API version 8开始支持,从API version 9开始废弃。建议使用[notificationManager.SourceType](js-apis-notificationManager.md#sourcetype)替代
| 名称 | 值 | 说明 |
| -------------------- | --- | -------------------- |
| TYPE_NORMAL | 0 | 一般通知。 |
| TYPE_CONTINUOUS | 1 | 连续通知。 |
| TYPE_TIMER | 2 | 计划通知。 |
## RemoveReason<sup>9+</sup>
## RemoveReason<sup>9+</sup>
<sup>deprecated</sup>
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
: 此接口为系统接口,三方应用不支持调用。
> **说明:**
> 从 API version 9开始支持,从API version 9开始废弃。建议使用[notificationManager.RemoveReason](js-apis-notificationSubscribe.md#removereason)替代
| 名称 | 值 | 说明 |
| -------------------- | --- | -------------------- |
| CLICK_REASON_REMOVE
<sup>
9+
</sup>
| 1 | 点击通知后删除通知。 |
...
...
zh-cn/application-dev/reference/apis/js-apis-notificationManager.md
浏览文件 @
a8b830b1
...
...
@@ -3859,6 +3859,87 @@ notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data) =>
});
```
## notificationManager.on<sup>10+</sup>
on(type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void;
注册通知监听回调。通知服务将通知信息回调给校验程序,校验程序返回校验结果决定该通知是否发布,如营销类通知发布频率控制等。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
:此接口为系统接口,三方应用不支持调用。
**需要权限**
:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------- | ---- | -------------- |
| type | string | 是 | 回调函数类型名,固定为'checkNotification'。 |
| callback | (checkInfo: [NotificationCheckInfo]) => [NotificationCheckResult] | 是 | 消息验证函数指针。 |
**错误码:**
错误码详细介绍请参考
[
errcode-notification
](
../errorcodes/errorcode-notification.md
)
。
| 错误码ID | 错误信息 |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
**示例:**
```
ts
try
{
notificationManager
.
on
(
"
checkNotification
"
,
OnCheckNotification
);
}
catch
(
error
){
console
.
info
(
`notificationManager.on error:
${
JSON
.
stringify
(
error
)}
`
);
}
function
OnCheckNotification
(
info
:
notificationManager
.
NotificationCheckInfo
)
{
console
.
info
(
`====>OnCheckNotification info:
${
JSON
.
stringify
(
info
)}
`
);
if
(
info
.
notificationId
==
1
){
return
{
code
:
1
,
message
:
"
testMsg1
"
}
}
else
{
return
{
code
:
0
,
message
:
"
testMsg0
"
}
}
}
```
## notificationManager.off<sup>10+</sup>
off(type: 'checkNotification', callback?: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void;
取消通知监听回调。
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
:此接口为系统接口,三方应用不支持调用。
**需要权限**
:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------- | ---- | -------------- |
| type | string | 是 | 回调函数类型名,固定为'checkNotification'。 |
| callback | (checkInfo: [NotificationCheckInfo]) => [NotificationCheckResult] | 是 | 消息验证函数指针。 |
**错误码:**
错误码详细介绍请参考
[
errcode-notification
](
../errorcodes/errorcode-notification.md
)
。
| 错误码ID | 错误信息 |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
**示例:**
```
ts
try
{
notificationManager
.
off
(
"
checkNotification
"
);
}
catch
(
error
){
console
.
info
(
`notificationManager.off error:
${
JSON
.
stringify
(
error
)}
`
);
}
```
## DoNotDisturbDate
...
...
@@ -3866,11 +3947,11 @@ notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data) =>
**系统API**
:此接口为系统接口,三方应用不支持调用。
| 名称 | 类型 |
可读 | 可写
| 说明 |
| 名称 | 类型 |
只读 | 必填
| 说明 |
| ----- | ------------------------------------- | ---- | ---- | ---------------------- |
| type |
[
DoNotDisturbType
](
#donotdisturbtype
)
|
是
| 是 | 免打扰设置的时间类型。 |
| begin | Date |
是
| 是 | 免打扰设置的起点时间。 |
| end | Date |
是
| 是 | 免打扰设置的终点时间。 |
| type |
[
DoNotDisturbType
](
#donotdisturbtype
)
|
否
| 是 | 免打扰设置的时间类型。 |
| begin | Date |
否
| 是 | 免打扰设置的起点时间。 |
| end | Date |
否
| 是 | 免打扰设置的终点时间。 |
## DoNotDisturbType
...
...
@@ -3951,3 +4032,30 @@ notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data) =>
| TYPE_NORMAL | 0 | 一般通知。 |
| TYPE_CONTINUOUS | 1 | 连续通知。 |
| TYPE_TIMER | 2 | 计划通知。 |
## NotificationCheckInfo<sup>10+</sup>
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
:此接口为系统接口,三方应用不支持调用。
**需要权限**
:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER
| 名称 | 类型 | 只读 | 必填 | 说明 |
| ----- | ------------------------------------- | ---- | ---- | ---------------------- |
| bundleName | string | 否 | 是 | bundle名称。 |
| notificationId | number | 否 | 是 | 通知Id。 |
| contentType |
[
ContentType
](
#contenttype
)
| 否 | 是 | 通知类型。 |
## NotificationCheckResult<sup>10+</sup>
**系统能力**
:SystemCapability.Notification.Notification
**系统API**
:此接口为系统接口,三方应用不支持调用。
**需要权限**
:ohos.permission.NOTIFICATION_CONTROLLER 和 ohos.permission.NOTIFICATION_AGENT_CONTROLLER
| 名称 | 类型 | 只读 | 必填 | 说明 |
| ----- | ------------------------------------- | ---- | ---- | ---------------------- |
| code | number | 否 | 是 | 0-display, 1-no display。 |
| message | string | 否 | 是 | 结果信息。 |
zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md
浏览文件 @
a8b830b1
...
...
@@ -272,7 +272,7 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | ----------------------------------| ---- | -------------------- |
| bundle |
[
BundleOption
](
js-apis-inner-notification-notificationCommonDef.md#bundleoption
)
| 是 | 指定应用的包信息。 |
| notificationKey |
[
NotificationKey
](
js-apis-notification.md
#notificationkey
)
| 是 | 通知键值。 |
| notificationKey |
[
NotificationKey
](
#notificationkey
)
| 是 | 通知键值。 |
| reason |
[
RemoveReason
](
#removereason
)
| 是 | 通知删除原因。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 删除指定通知回调函数。 |
...
...
@@ -328,7 +328,7 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | --------------- | ---- | ---------- |
| bundle |
[
BundleOption
](
js-apis-inner-notification-notificationCommonDef.md#bundleoption
)
| 是 | 指定应用的包信息。 |
| notificationKey |
[
NotificationKey
](
(js-apis-notification.md#notificationkey
)
) | 是 | 通知键值。 |
| notificationKey |
[
NotificationKey
](
#notificationkey
)
| 是 | 通知键值。 |
| reason |
[
RemoveReason
](
#removereason
)
| 是 | 通知删除原因。 |
**错误码:**
...
...
@@ -618,7 +618,7 @@ let userId = 1;
notificationSubscribe
.
removeAll
(
userId
,
removeAllCallback
);
```
## Notification.removeAll
## Notification
Subscribe
.removeAll
removeAll(userId: number): Promise
\<
void>
...
...
@@ -663,6 +663,15 @@ let userId = 1;
notificationSubscribe
.
removeAll
(
userId
,
removeAllCallback
);
```
## NotificationKey
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 类型 | 只读 | 必填 | 说明 |
| ----- | ------ | ---- | --- | -------- |
| id | number | 否 | 是 | 通知ID。 |
| label | string | 否 | 否 | 通知标签。 |
## RemoveReason
**系统能力**
:SystemCapability.Notification.Notification
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录