diff --git a/zh-cn/application-dev/reference/apis/js-apis-commonEvent.md b/zh-cn/application-dev/reference/apis/js-apis-commonEvent.md index c244934d6de61e238ede1f5b41a98c18574c55a2..809e2c9f81e162c1616f5d3cc55e9be5a6ec8a23 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-commonEvent.md +++ b/zh-cn/application-dev/reference/apis/js-apis-commonEvent.md @@ -3,7 +3,9 @@ > **说明:** > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -## 权限列表 +## Support + +权限列表。 | 系统公共事件宏 | 系统公共事件名称 | 订阅者所需权限 | | ------------ | ------------------ | ---------------------- | @@ -514,601 +516,3 @@ CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); //取消订阅公共事件 CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); ``` - -## CommonEventPublishData - -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------------------- | -------- | -------------------- | ---- | ---------------------------- | -| bundleName | 只读 | string | 否 | 表示包名称 | -| code | 只读 | number | 否 | 表示公共事件的结果代码 | -| data | 只读 | string | 否 | 表示公共事件的自定义结果数据 | -| subscriberPermissions | 只读 | Array\ | 否 | 表示订阅者的权限 | -| isOrdered | 只读 | boolean | 否 | 表示是否是有序事件 | -| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | - -## CommonEventSubscribeInfo - -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------------- | -------- | -------------- | ---- | ------------------------------------------------------------ | -| events | 只读 | Array\ | 是 | 表示要发送的公共事件 | -| publisherPermission | 只读 | string | 否 | 表示发布者的权限 | -| publisherDeviceId | 只读 | string | 否 | 表示设备ID,该值必须是同一ohos网络上的现有设备ID | -| userId | 只读 | number | 否 | 表示用户ID。此参数是可选的,默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。 | -| priority | 只读 | number | 否 | 表示订阅者的优先级。值的范围是-100到1000 | - -## CommonEventData - -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | -------------------- | ---- | ------------------------------------------------------- | -| event | 只读 | string | 是 | 表示当前接收的公共事件名称 | -| bundleName | 只读 | string | 否 | 表示包名称 | -| code | 只读 | number | 否 | 表示公共事件的结果代码,用于传递int类型的数据 | -| data | 只读 | string | 否 | 表示公共事件的自定义结果数据,用于传递string类型的数据< | -| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | - -## CommonEventSubscriber - -### getCode - -getCode(callback: AsyncCallback\): void - -获取公共事件的结果代码(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | ------------------ | -| callback | AsyncCallback\ | 是 | 公共事件的结果代码 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -getCode() { -function getCodeCallback(err, Code) { - if (err.code) { - console.error("getCode failed " + JSON.stringify(err)); - } else { - console.info("getCode " + JSON.stringify(Code)); - } -} -subscriber.getCode(getCodeCallback); -``` - -### getCode - -getCode(): Promise\ - -获取公共事件的结果代码(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**返回值:** - -| 类型 | 说明 | -| ---------------- | -------------------- | -| Promise\ | 公共事件的结果代码。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.getCode().then((Code) => { - console.info("getCode " + JSON.stringify(Code)); -}).catch((err) => { - console.error("getCode failed " + JSON.stringify(err)); -}); -``` - -### setCode - -setCode(code: number, callback: AsyncCallback\): void - -设置公共事件的结果代码(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | ---------------------- | -| code | number | 是 | 公共事件的结果代码。 | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function setCodeCallback(err) { - if (err.code) { - console.error("setCode failed " + JSON.stringify(err)); - } else { - console.info("setCode"); - } -} -subscriber.setCode(1, setCodeCallback); -``` - -### setCode - -setCode(code: number): Promise\ - -设置公共事件的结果代码(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| ------ | ------ | ---- | ------------------ | -| code | number | 是 | 公共事件的结果代码 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.setCode(1).then(() => { - console.info("setCode"); -}).catch((err) => { - console.error("setCode failed " + JSON.stringify(err)); -}); -``` - -### getData - -getData(callback: AsyncCallback\): void - -获取公共事件的结果数据(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 公共事件的结果数据。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function getDataCallback(err, Data) { - if (err.code) { - console.error("getData failed " + JSON.stringify(err)); - } else { - console.info("getData " + JSON.stringify(Data)); - } -} -subscriber.getData(getDataCallback); -``` - -### getData - -getData(): Promise\ - -获取公共事件的结果数据(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**返回值:** - -| 类型 | 说明 | -| ---------------- | ------------------ | -| Promise\ | 公共事件的结果数据 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.getData().then((Data) => { - console.info("getData " + JSON.stringify(Data)); -}).catch((err) => { - console.error("getData failed " + JSON.stringify(err)); -}); -``` - -### setData - -setData(data: string, callback: AsyncCallback\): void - -设置公共事件的结果数据(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | -------------------- | -| data | string | 是 | 公共事件的结果数据 | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function setDataCallback(err) { - if (err.code) { - console.error("setData failed " + JSON.stringify(err)); - } else { - console.info("setData"); - } -} -subscriber.setData("publish_data_changed", setDataCallback); -``` - -### setData - -setData(data: string): Promise\ - -设置公共事件的结果数据(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| ------ | ------ | ---- | -------------------- | -| data | string | 是 | 公共事件的结果数据。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.setData("publish_data_changed").then(() => { - console.info("setData"); -}).catch((err) => { - console.error("setData failed " + JSON.stringify(err)); -}); -``` - -### setCodeAndData - -setCodeAndData(code: number, data: string, callback:AsyncCallback\): void - -设置公共事件的结果代码和结果数据(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | ---------------------- | -| code | number | 是 | 公共事件的结果代码。 | -| data | string | 是 | 公共事件的结果数据。 | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function setCodeDataCallback(err) { - if (err.code) { - console.error("setCodeAndData failed " + JSON.stringify(err)); - } else { - console.info("setCodeDataCallback"); - } -} -subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback); -``` - -### setCodeAndData - -setCodeAndData(code: number, data: string): Promise\ - -设置公共事件的结果代码和结果数据(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| ------ | ------ | ---- | -------------------- | -| code | number | 是 | 公共事件的结果代码。 | -| data | string | 是 | 公共事件的结果数据。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.setCodeAndData(1, "publish_data_changed").then(() => { - console.info("setCodeAndData"); -}).catch((err) => { - console.info("setCodeAndData failed " + JSON.stringify(err)); -}); -``` - -### isOrderedCommonEvent - -isOrderedCommonEvent(callback: AsyncCallback\): void - -查询当前公共事件的是否为有序公共事件(callback形式)。 - -返回true代表是有序公共事件,false代表不是有序公共事件。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | 是 | 当前公共事件的是否为有序公共事件。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function isOrderedCallback(err, isOrdered) { - if (err.code) { - console.error("isOrderedCommonEvent failed " + JSON.stringify(err)); - } else { - console.info("isOrdered " + JSON.stringify(isOrdered)); - } -} -subscriber.isOrderedCommonEvent(isOrderedCallback); -``` - -### isOrderedCommonEvent - -isOrderedCommonEvent(): Promise\ - -查询当前公共事件的是否为有序公共事件(Promise形式)。 - -返回true代表是有序公共事件,false代表不是有序公共事件。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**返回值:** - -| 类型 | 说明 | -| ----------------- | -------------------------------- | -| Promise\ | 当前公共事件的是否为有序公共事件 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.isOrderedCommonEvent().then((isOrdered) => { - console.info("isOrdered " + JSON.stringify(isOrdered)); -}).catch((err) => { - console.error("isOrdered failed " + JSON.stringify(err)); -}); -``` - -### abortCommonEvent - -abortCommonEvent(callback: AsyncCallback\): void - -取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 取消当前的公共事件。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function abortCallback(err) { - if (err.code) { - console.error("abortCommonEvent failed " + JSON.stringify(err)); - } else { - console.info("abortCommonEvent"); - } -} -subscriber.abortCommonEvent(abortCallback); -``` - -### abortCommonEvent - -abortCommonEvent(): Promise\ - -取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.abortCommonEvent().then(() => { - console.info("abortCommonEvent"); -}).catch((err) => { - console.error("abortCommonEvent failed " + JSON.stringify(err)); -}); -``` - -### clearAbortCommonEvent - -clearAbortCommonEvent(callback: AsyncCallback\): void - -清除当前公共事件的取消状态,仅对有序公共事件有效(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function clearAbortCallback(err) { - if (err.code) { - console.error("clearAbortCommonEvent failed " + JSON.stringify(err)); - } else { - console.info("clearAbortCommonEvent"); - } -} -subscriber.clearAbortCommonEvent(clearAbortCallback); -``` - -### clearAbortCommonEvent - -clearAbortCommonEvent(): Promise\ - -清除当前公共事件的取消状态,仅对有序公共事件有效(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.clearAbortCommonEvent().then(() => { - console.info("clearAbortCommonEvent"); -}).catch((err) => { - console.error("clearAbortCommonEvent failed " + JSON.stringify(err)); -}); -``` - -### getAbortCommonEvent - -getAbortCommonEvent(callback: AsyncCallback\): void - -获取当前有序公共事件是否取消的状态(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | 是 | 表示当前有序公共事件是否取消的状态 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function getAbortCallback(err, AbortCommonEvent) { - if (err.code) { - console.error("getAbortCommonEvent failed " + JSON.stringify(err)); - } else { - console.info("AbortCommonEvent " + AbortCommonEvent) - } -} -subscriber.getAbortCommonEvent(getAbortCallback); -``` - -### getAbortCommonEvent - -getAbortCommonEvent(): Promise\ - -获取当前有序公共事件是否取消的状态(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**返回值:** - -| 类型 | 说明 | -| ----------------- | ---------------------------------- | -| Promise\ | 表示当前有序公共事件是否取消的状态 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.getAbortCommonEvent().then((AbortCommonEvent) => { - console.info("AbortCommonEvent " + JSON.stringify(AbortCommonEvent)); -}).catch((err) => { - console.error("getAbortCommonEvent failed " + JSON.stringify(err)); -}); -``` - -### getSubscribeInfo - -getSubscribeInfo(callback: AsyncCallback\): void - -获取订阅者的订阅信息(callback形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ------------------------------------------------------------ | ---- | ---------------------- | -| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 是 | 表示订阅者的订阅信息。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -//设置有序公共事件的结果数据回调 -function getSubscribeInfoCallback(err, SubscribeInfo) { - if (err.code) { - console.error("getSubscribeInfo failed " + JSON.stringify(err)); - } else { - console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo)); - } -} -subscriber.getSubscribeInfo(getSubscribeInfoCallback); -``` - -### getSubscribeInfo - -getSubscribeInfo(): Promise\ - -获取订阅者的订阅信息(Promise形式)。 - -**系统能力:** SystemCapability.Notification.CommonEvent - -**返回值:** - -| 类型 | 说明 | -| ------------------------------------------------------------ | ---------------------- | -| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 表示订阅者的订阅信息。 | - -**示例:** - -```js -var subscriber; //创建成功的订阅者对象 - -subscriber.getSubscribeInfo().then((SubscribeInfo) => { - console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo)); -}).catch((err) => { - console.error("getSubscribeInfo failed " + JSON.stringify(err)); -}); -``` - diff --git a/zh-cn/application-dev/reference/apis/js-apis-commonEventData.md b/zh-cn/application-dev/reference/apis/js-apis-commonEventData.md new file mode 100644 index 0000000000000000000000000000000000000000..189cc038db96416207b161bd174dd753215d04a3 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-commonEventData.md @@ -0,0 +1,16 @@ +# 公共事件数据 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## CommonEventData + +**系统能力:**以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent + +| 名称 | 读写属性 | 类型 | 必填 | 描述 | +| ---------- | -------- | -------------------- | ---- | ------------------------------------------------------- | +| event | 只读 | string | 是 | 表示当前接收的公共事件名称 | +| bundleName | 只读 | string | 否 | 表示包名称 | +| code | 只读 | number | 否 | 表示公共事件的结果代码,用于传递int类型的数据 | +| data | 只读 | string | 否 | 表示公共事件的自定义结果数据,用于传递string类型的数据< | +| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-commonEventPublishData.md b/zh-cn/application-dev/reference/apis/js-apis-commonEventPublishData.md new file mode 100644 index 0000000000000000000000000000000000000000..8f9a240fa4cf05cb1e65b5136a0e46b9a69d07b5 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-commonEventPublishData.md @@ -0,0 +1,19 @@ +# 公共事件内容和属性 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## CommonEventPublishData + +**系统能力:**以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent + +| 名称 | 读写属性 | 类型 | 必填 | 描述 | +| --------------------- | -------- | -------------------- | ---- | ---------------------------- | +| bundleName | 只读 | string | 否 | 表示包名称 | +| code | 只读 | number | 否 | 表示公共事件的结果代码 | +| data | 只读 | string | 否 | 表示公共事件的自定义结果数据 | +| subscriberPermissions | 只读 | Array\ | 否 | 表示订阅者的权限 | +| isOrdered | 只读 | boolean | 否 | 表示是否是有序事件 | +| isSticky | 只读 | boolean | 否 | 表示是否是粘性事件 | +| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | + diff --git a/zh-cn/application-dev/reference/apis/js-apis-commonEventSubscribeInfo.md b/zh-cn/application-dev/reference/apis/js-apis-commonEventSubscribeInfo.md new file mode 100644 index 0000000000000000000000000000000000000000..546a275e7be103559b8369ce14d65f906c5a15ba --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-commonEventSubscribeInfo.md @@ -0,0 +1,16 @@ +# 订阅者的信息 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## CommonEventSubscribeInfo + +**系统能力:**以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent + +| 名称 | 读写属性 | 类型 | 必填 | 描述 | +| ------------------- | -------- | -------------- | ---- | ------------------------------------------------------------ | +| events | 只读 | Array\ | 是 | 表示要发送的公共事件 | +| publisherPermission | 只读 | string | 否 | 表示发布者的权限 | +| publisherDeviceId | 只读 | string | 否 | 表示设备ID,该值必须是同一ohos网络上的现有设备ID | +| userId | 只读 | number | 否 | 表示用户ID。此参数是可选的,默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。 | +| priority | 只读 | number | 否 | 表示订阅者的优先级。值的范围是-100到1000 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-commonEventSubscriber.md b/zh-cn/application-dev/reference/apis/js-apis-commonEventSubscriber.md new file mode 100644 index 0000000000000000000000000000000000000000..3a551aa5ecbe01b8a00a3897bc559b2fdccbba95 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-commonEventSubscriber.md @@ -0,0 +1,609 @@ +# 公共事件的订阅者 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## CommonEventSubscriber + +### getCode + +getCode(callback: AsyncCallback\): void + +获取公共事件的结果代码(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | ---------------------- | ---- | ------------------ | +| callback | AsyncCallback\ | 是 | 公共事件的结果代码 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +getCode() { +function getCodeCallback(err, Code) { + if (err.code) { + console.error("getCode failed " + JSON.stringify(err)); + } else { + console.info("getCode " + JSON.stringify(Code)); + } +} +subscriber.getCode(getCodeCallback); +``` + +### getCode + +getCode(): Promise\ + +获取公共事件的结果代码(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**返回值:** + +| 类型 | 说明 | +| ---------------- | -------------------- | +| Promise\ | 公共事件的结果代码。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.getCode().then((Code) => { + console.info("getCode " + JSON.stringify(Code)); +}).catch((err) => { + console.error("getCode failed " + JSON.stringify(err)); +}); +``` + +### setCode + +setCode(code: number, callback: AsyncCallback\): void + +设置公共事件的结果代码(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | -------------------- | ---- | ---------------------- | +| code | number | 是 | 公共事件的结果代码。 | +| callback | AsyncCallback\ | 是 | 表示被指定的回调方法。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function setCodeCallback(err) { + if (err.code) { + console.error("setCode failed " + JSON.stringify(err)); + } else { + console.info("setCode"); + } +} +subscriber.setCode(1, setCodeCallback); +``` + +### setCode + +setCode(code: number): Promise\ + +设置公共事件的结果代码(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| ------ | ------ | ---- | ------------------ | +| code | number | 是 | 公共事件的结果代码 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.setCode(1).then(() => { + console.info("setCode"); +}).catch((err) => { + console.error("setCode failed " + JSON.stringify(err)); +}); +``` + +### getData + +getData(callback: AsyncCallback\): void + +获取公共事件的结果数据(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | ---------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | 是 | 公共事件的结果数据。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function getDataCallback(err, Data) { + if (err.code) { + console.error("getData failed " + JSON.stringify(err)); + } else { + console.info("getData " + JSON.stringify(Data)); + } +} +subscriber.getData(getDataCallback); +``` + +### getData + +getData(): Promise\ + +获取公共事件的结果数据(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**返回值:** + +| 类型 | 说明 | +| ---------------- | ------------------ | +| Promise\ | 公共事件的结果数据 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.getData().then((Data) => { + console.info("getData " + JSON.stringify(Data)); +}).catch((err) => { + console.error("getData failed " + JSON.stringify(err)); +}); +``` + +### setData + +setData(data: string, callback: AsyncCallback\): void + +设置公共事件的结果数据(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | -------------------- | ---- | -------------------- | +| data | string | 是 | 公共事件的结果数据 | +| callback | AsyncCallback\ | 是 | 表示被指定的回调方法 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function setDataCallback(err) { + if (err.code) { + console.error("setData failed " + JSON.stringify(err)); + } else { + console.info("setData"); + } +} +subscriber.setData("publish_data_changed", setDataCallback); +``` + +### setData + +setData(data: string): Promise\ + +设置公共事件的结果数据(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| ------ | ------ | ---- | -------------------- | +| data | string | 是 | 公共事件的结果数据。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.setData("publish_data_changed").then(() => { + console.info("setData"); +}).catch((err) => { + console.error("setData failed " + JSON.stringify(err)); +}); +``` + +### setCodeAndData + +setCodeAndData(code: number, data: string, callback:AsyncCallback\): void + +设置公共事件的结果代码和结果数据(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | -------------------- | ---- | ---------------------- | +| code | number | 是 | 公共事件的结果代码。 | +| data | string | 是 | 公共事件的结果数据。 | +| callback | AsyncCallback\ | 是 | 表示被指定的回调方法。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function setCodeDataCallback(err) { + if (err.code) { + console.error("setCodeAndData failed " + JSON.stringify(err)); + } else { + console.info("setCodeDataCallback"); + } +} +subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback); +``` + +### setCodeAndData + +setCodeAndData(code: number, data: string): Promise\ + +设置公共事件的结果代码和结果数据(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| ------ | ------ | ---- | -------------------- | +| code | number | 是 | 公共事件的结果代码。 | +| data | string | 是 | 公共事件的结果数据。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.setCodeAndData(1, "publish_data_changed").then(() => { + console.info("setCodeAndData"); +}).catch((err) => { + console.info("setCodeAndData failed " + JSON.stringify(err)); +}); +``` + +### isOrderedCommonEvent + +isOrderedCommonEvent(callback: AsyncCallback\): void + +查询当前公共事件的是否为有序公共事件(callback形式)。 + +返回true代表是有序公共事件,false代表不是有序公共事件。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | ----------------------- | ---- | ---------------------------------- | +| callback | AsyncCallback\ | 是 | 当前公共事件的是否为有序公共事件。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function isOrderedCallback(err, isOrdered) { + if (err.code) { + console.error("isOrderedCommonEvent failed " + JSON.stringify(err)); + } else { + console.info("isOrdered " + JSON.stringify(isOrdered)); + } +} +subscriber.isOrderedCommonEvent(isOrderedCallback); +``` + +### isOrderedCommonEvent + +isOrderedCommonEvent(): Promise\ + +查询当前公共事件的是否为有序公共事件(Promise形式)。 + +返回true代表是有序公共事件,false代表不是有序公共事件。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**返回值:** + +| 类型 | 说明 | +| ----------------- | -------------------------------- | +| Promise\ | 当前公共事件的是否为有序公共事件 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.isOrderedCommonEvent().then((isOrdered) => { + console.info("isOrdered " + JSON.stringify(isOrdered)); +}).catch((err) => { + console.error("isOrdered failed " + JSON.stringify(err)); +}); +``` + +### abortCommonEvent + +abortCommonEvent(callback: AsyncCallback\): void + +取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | -------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | 是 | 取消当前的公共事件。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function abortCallback(err) { + if (err.code) { + console.error("abortCommonEvent failed " + JSON.stringify(err)); + } else { + console.info("abortCommonEvent"); + } +} +subscriber.abortCommonEvent(abortCallback); +``` + +### abortCommonEvent + +abortCommonEvent(): Promise\ + +取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.abortCommonEvent().then(() => { + console.info("abortCommonEvent"); +}).catch((err) => { + console.error("abortCommonEvent failed " + JSON.stringify(err)); +}); +``` + +### clearAbortCommonEvent + +clearAbortCommonEvent(callback: AsyncCallback\): void + +清除当前公共事件的取消状态,仅对有序公共事件有效(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | -------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | 是 | 表示被指定的回调方法 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function clearAbortCallback(err) { + if (err.code) { + console.error("clearAbortCommonEvent failed " + JSON.stringify(err)); + } else { + console.info("clearAbortCommonEvent"); + } +} +subscriber.clearAbortCommonEvent(clearAbortCallback); +``` + +### clearAbortCommonEvent + +clearAbortCommonEvent(): Promise\ + +清除当前公共事件的取消状态,仅对有序公共事件有效(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.clearAbortCommonEvent().then(() => { + console.info("clearAbortCommonEvent"); +}).catch((err) => { + console.error("clearAbortCommonEvent failed " + JSON.stringify(err)); +}); +``` + +### getAbortCommonEvent + +getAbortCommonEvent(callback: AsyncCallback\): void + +获取当前有序公共事件是否取消的状态(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | ----------------------- | ---- | ---------------------------------- | +| callback | AsyncCallback\ | 是 | 表示当前有序公共事件是否取消的状态 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function getAbortCallback(err, AbortCommonEvent) { + if (err.code) { + console.error("getAbortCommonEvent failed " + JSON.stringify(err)); + } else { + console.info("AbortCommonEvent " + AbortCommonEvent) + } +} +subscriber.getAbortCommonEvent(getAbortCallback); +``` + +### getAbortCommonEvent + +getAbortCommonEvent(): Promise\ + +获取当前有序公共事件是否取消的状态(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**返回值:** + +| 类型 | 说明 | +| ----------------- | ---------------------------------- | +| Promise\ | 表示当前有序公共事件是否取消的状态 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.getAbortCommonEvent().then((AbortCommonEvent) => { + console.info("AbortCommonEvent " + JSON.stringify(AbortCommonEvent)); +}).catch((err) => { + console.error("getAbortCommonEvent failed " + JSON.stringify(err)); +}); +``` + +### getSubscribeInfo + +getSubscribeInfo(callback: AsyncCallback\): void + +获取订阅者的订阅信息(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | ------------------------------------------------------------ | ---- | ---------------------- | +| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 是 | 表示订阅者的订阅信息。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +//设置有序公共事件的结果数据回调 +function getSubscribeInfoCallback(err, SubscribeInfo) { + if (err.code) { + console.error("getSubscribeInfo failed " + JSON.stringify(err)); + } else { + console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo)); + } +} +subscriber.getSubscribeInfo(getSubscribeInfoCallback); +``` + +### getSubscribeInfo + +getSubscribeInfo(): Promise\ + +获取订阅者的订阅信息(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------------------------------ | ---------------------- | +| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 表示订阅者的订阅信息。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.getSubscribeInfo().then((SubscribeInfo) => { + console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo)); +}).catch((err) => { + console.error("getSubscribeInfo failed " + JSON.stringify(err)); +}); +``` + +### finishCommonEvent + +finishCommonEvent(callback: AsyncCallback\): void + +结束当前已排序的公共事件(callback形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 描述 | +| -------- | -------------------- | ---- | -------------------------------- | +| callback | AsyncCallback\ | 是 | 表示排序的公共事件结束后的回调函数。 | + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +function finishCommonEventCallback() { + console.log("--------- finishCommonEventCallback ----------"); +} + +subscriber.finishCommonEvent(finishCommonEventCallback); +``` + +### finishCommonEvent + +finishCommonEvent(): Promise\ + +结束当前已排序的公共事件(Promise形式)。 + +**系统能力**:SystemCapability.Notification.CommonEvent + +**示例:** + +```js +var subscriber; //创建成功的订阅者对象 + +subscriber.finishCommonEvent() + .then(() => { + console.info("--------- finishCommonEventCallback ----------"); + }) +``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notification.md b/zh-cn/application-dev/reference/apis/js-apis-notification.md index 2d61c59625bfb78f5ef66608b0fe7eaac5bc884b..220b08370f7f8076732e6d49d4ea438d43fcad38 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-notification.md +++ b/zh-cn/application-dev/reference/apis/js-apis-notification.md @@ -80,7 +80,7 @@ Notification.publish(notificationRequest).then(() => { ## Notification.publish8+ -publish(request: NotificationRequest, userId: number, callback: AsyncCallback): void +publish(request: NotificationRequest, userId: number, callback: AsyncCallback\): void 发布通知(callback形式)。 @@ -120,7 +120,7 @@ Notification.publish(notificationRequest, userId, publishCallback); ## Notification.publish8+ -publish(request: NotificationRequest, userId: number): Promise +publish(request: NotificationRequest, userId: number): Promise\ 发布通知(Promise形式)。 @@ -186,7 +186,7 @@ Notification.cancel(0, "label", cancelCallback) ## Notification.cancel -cancel(id:number, label?:string): Promise\ +cancel(id:number, label? :string): Promise\ 取消与指定id相匹配的已发布通知,label可以指定也可以不指定(Promise形式)。 @@ -487,7 +487,7 @@ Notification.getSlot(slotType, getSlotCallback) ## Notification.getSlot -getSlot(slotType): Promise\ +getSlot(slotType: SlotType): Promise\ 获取一个通知通道(Promise形式)。 @@ -544,7 +544,7 @@ Notification.getSlots(getSlotsCallback) ## Notification.getSlots -getSlots(): Promise> +getSlots(): Promise\> 获取此应用程序的所有通知通道(Promise形式)。 @@ -701,7 +701,7 @@ Notification.subscribe(subscriber, info, subscribeCallback); ## Notification.subscribe -subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\); void +subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void 订阅通知并指定订阅信息(callback形式)。 @@ -1504,7 +1504,7 @@ Notification.removeAll().then(() => { ## Notification.removeAll8+ -removeAll(userId: number, callback: AsyncCallback): void +removeAll(userId: number, callback: AsyncCallback\): void 删除所有通知(callback形式)。 @@ -1531,7 +1531,7 @@ Notification.removeAll(userId, removeAllCallback); ## Notification.removeAll8+ -removeAll(userId: number): Promise +removeAll(userId: number): Promise\ 删除所有通知(Promise形式)。 @@ -2168,7 +2168,7 @@ Notification.isSupportTemplate(templateName).then((data) => { ## Notification.requestEnableNotification8+ -requestEnabledNotification(callback: AsyncCallback\): void +requestEnableNotification(callback: AsyncCallback\): void 应用请求通知使能。 @@ -2194,7 +2194,7 @@ Notification.requestEnabledNotification(requestEnabledNotificationCallback); ## Notification.requestEnableNotification8+ -requestEnabledNotification(): Promise +requestEnableNotification(): Promise\ 应用请求通知使能。 @@ -2241,7 +2241,7 @@ Notification.enableDistributed(enable, enabledNotificationCallback); ## Notification.enableDistributed8+ -enableDistributed(enable: boolean): Promise +enableDistributed(enable: boolean): Promise\ 设置设备是否支持分布式通知。 @@ -2267,7 +2267,7 @@ Notification.enableDistributed(enable) ## Notification.isDistributedEnabled8+ -isDistributedEnabled(callback: AsyncCallback): void +isDistributedEnabled(callback: AsyncCallback\): void 获取设备是否支持分布式通知。 @@ -2293,7 +2293,7 @@ Notification.enableDistributed(isDistributedEnabledCallback); ## Notification.isDistributedEnabled8+ -isDistributedEnabled(): Promise +isDistributedEnabled(): Promise\ 获取设备是否支持分布式通知。 @@ -2317,7 +2317,7 @@ Notification.isDistributedEnabled() ## Notification.enableDistributedByBundle8+ -enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void +enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void 根据应用的包设置应用程序是否支持分布式通知。 @@ -2381,7 +2381,7 @@ Notification.enableDistributedByBundle(bundle, enable) ## Notification.isDistributedEnabledByBundle8+ -isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback): void +isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\): void 根据应用的包获取应用程序是否支持分布式通知。 @@ -2412,7 +2412,7 @@ Notification.enableDistributedByBundle(bundle, isDistributedEnabledByBundleCallb ## Notification.isDistributedEnabledByBundle8+ -isDistributedEnabledByBundle(bundle: BundleOption): Promise +isDistributedEnabledByBundle(bundle: BundleOption): Promise\ 根据应用的包获取应用程序是否支持分布式通知。 @@ -2446,7 +2446,7 @@ Notification.isDistributedEnabledByBundle(bundle) ## Notification.getDeviceRemindType8+ -getDeviceRemindType(callback: AsyncCallback): void +getDeviceRemindType(callback: AsyncCallback\): void 获取通知的提醒方式。 @@ -2472,7 +2472,7 @@ Notification.getDeviceRemindType(getDeviceRemindTypeCallback); ## Notification.getDeviceRemindType8+ -getDeviceRemindType(): Promise +getDeviceRemindType(): Promise\ 获取通知的提醒方式。 @@ -2493,366 +2493,8 @@ Notification.getDeviceRemindType() }); ``` -## Notification.show -show(options?: ShowNotificationOptions): void - -展示通知事件。 - -**系统能力**:SystemCapability.Notification.Notification - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------ | ---- | ---------------- | -| options | ShowNotificationOptions | 否 | 需要展示通知的参数 | - -**示例:** - -```javascript -var options = { - contentTitle: 'contentTitle', - contentText: 'contentText', - clickAction: { - bundleName: 'bundleName', - abilityName: 'abilityName', - uri: 'uri', - } -}; - -Notification.show(options); -``` - - - -## NotificationSubscriber -### onConsume - -onConsume?:(data: [SubscribeCallbackData](#subscribecallbackdata)) - -接收通知回调函数。 - -**系统能力**:SystemCapability.Notification.Notification - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------------------------ | ---- | -------------------------- | -| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | 是 | 回调返回接收到的通知信息。 | - -**示例:** - -```javascript -function subscribeCallback(err) { - if (err.code) { - console.info("subscribe failed " + JSON.stringify(err)); - } else { - console.info("subscribeCallback"); - } -}; - -function onConsumeCallback(data) { - console.info('===> onConsume in test'); - let req = data.request; - console.info('===> onConsume callback req.id:' + req.id); - let wantAgent = data.wantAgent; - wantAgent .getWant(wantAgent) - .then((data1) => { - console.log('===> getWant success want:' + JSON.stringfy(data1)); - }) - .catch((err) => { - console.error('===> getWant failed because' + JSON.stringfy(err)); - }); - console.info('===> onConsume callback req.wantAgent:' + JSON.stringfy(req.wantAgent)); -}; - -var subscriber = { - onConsume: onConsumeCallback -}; - -Notification.subscribe(subscriber, subscribeCallback); -``` - -### onCancel - -onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) - -删除通知回调函数。 - -**系统能力**:SystemCapability.Notification.Notification - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------------------------ | ---- | -------------------------- | -| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | 是 | 回调返回接收到的通知信息。 | - -**示例:** - -```javascript -function subscribeCallback(err) { - if (err.code) { - console.info("subscribe failed " + JSON.stringify(err)); - } else { - console.info("subscribeCallback"); - } -}; - -function onCancelCallback(data) { - console.info('===> onCancel in test'); - let req = data.request; - console.info('===> onCancel callback req.id:' + req.id); -} - -var subscriber = { - onCancel: onCancelCallback -}; - -Notification.subscribe(subscriber, subscribeCallback); -``` - -### onUpdate - -onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap)) - -更新通知排序回调函数。 - -**系统能力**:SystemCapability.Notification.Notification - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------------------------ | ---- | -------------------------- | -| data | [NotificationSortingMap](#notificationsortingmap) | 是 | | - -**示例:** - -```javascript -function subscribeCallback(err) { - if (err.code) { - console.info("subscribe failed " + JSON.stringify(err)); - } else { - console.info("subscribeCallback"); - } -}; - -function onUpdateCallback() { - console.info('===> onUpdate in test'); -} - -var subscriber = { - onUpdate: onUpdateCallback -}; - -Notification.subscribe(subscriber, subscribeCallback); -``` - -### onConnect - -onConnect?:void - -注册订阅回调函数。 - -**系统能力**:SystemCapability.Notification.Notification - -**示例:** - -```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'); -} - -var subscriber = { - onConnect: onConnectCallback -}; - -Notification.subscribe(subscriber, subscribeCallback); -``` - -### onDisconnect - -onDisconnect?:void - -取消订阅回调函数。 - -**系统能力**:SystemCapability.Notification.Notification - -**示例:** - -```javascript -function subscribeCallback(err) { - if (err.code) { - console.info("subscribe failed " + JSON.stringify(err)); - } else { - console.info("subscribeCallback"); - } -}; - -function onDisconnectCallback() { - console.info('===> onDisconnect in test'); -} - -var subscriber = { - onDisconnect: onDisconnectCallback -}; - -Notification.subscribe(subscriber, subscribeCallback); -``` - -### onDestroy - -onDestroy?:void - -服务失联回调函数。 - -**系统能力**:SystemCapability.Notification.Notification - -**示例:** - -```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'); -} - -var subscriber = { - onDestroy: onDestroyCallback -}; - -Notification.subscribe(subscriber, subscribeCallback); -``` - -### onDoNotDisturbDateChange - -onDoNotDisturbDateChange?:(mode: Notification.[DoNotDisturbDate](#donotdisturbdate)) - -免打扰时间选项变更回调函数。 - -**系统能力**:SystemCapability.Notification.Notification - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------------------------ | ---- | -------------------------- | -| mode | Notification.[DoNotDisturbDate](#donotdisturbdate) | 是 | 回调返回免打扰时间选项变更。 | - -**示例:** -```javascript -function subscribeCallback(err) { - if (err.code) { - console.info("subscribe failed " + JSON.stringify(err)); - } else { - console.info("subscribeCallback"); - } -}; - -function onDoNotDisturbDateChangeCallback() { - console.info('===> onDoNotDisturbDateChange in test'); -} - -var subscriber = { - onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback -}; - -Notification.subscribe(subscriber, subscribeCallback); -``` - - -### onEnabledNotificationChanged - -onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata)) - -监听应用通知使能变化。 - -**系统能力**:SystemCapability.Notification.Notification - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------------------------ | ---- | -------------------------- | -| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata)\> | 是 | 回调返回监听到的应用信息。 | - -**示例:** - -```javascript -function subscribeCallback(err) { - if (err.code) { - console.info("subscribe failed " + JSON.stringify(err)); - } else { - console.info("subscribeCallback"); - } -}; - -function onEnabledNotificationChangedCallback(err, callbackData) { - if (err.code) { - console.info("subscribe failed " + JSON.stringify(err)); - } else { - console.info("bundle: ", callbackData.bundle); - console.info("uid: ", callbackData.uid); - console.info("enable: ", callbackData.enable); - } -}; - -var subscriber = { - onEnabledNotificationChanged: onEnabledNotificationChangedCallback -}; - -Notification.subscribe(subscriber, subscribeCallback); -``` - - - -## SubscribeCallbackData - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| --------------- | ---- | --- | ------------------------------------------------- | ---- | -------- | -| request | 是 | 否 | [NotificationRequest](#notificationrequest) | 是 | 通知内容。 | -| sortingMap | 是 | 否 | [NotificationSortingMap](#notificationsortingmap) | 否 | 排序信息。 | -| reason | 是 | 否 | number | 否 | 删除原因。 | -| sound | 是 | 否 | string | 否 | 通知声音。 | -| vibrationValues | 是 | 否 | Array\ | 否 | 通知震动。 | - -## NotificationSortingMap - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| -------------- | ---- | --- | ------------------------------------------------------------ | ---- | ---------------- | -| sortings | 是 | 否 | {[key: string]: [NotificationSorting](#notificationsorting)} | 是 | 通知排序信息数组。 | -| sortedHashCode | 是 | 否 | Array\ | 是 | 通知唯一标识数组。 | - - - -## NotificationSorting - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| -------- | ---- | --- | ------------------------------------- | ---- | ------------ | -| slot | 是 | 否 | [NotificationSlot](#notificationslot) | 是 | 通知通道内容。 | -| hashCode | 是 | 否 | string | 是 | 通知唯一标识。 | -| ranking | 是 | 否 | number | 是 | 通知排序序号。 | - - - -## DoNotDisturbDate +## DoNotDisturbDate8+ **系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification @@ -2877,89 +2519,6 @@ Notification.subscribe(subscriber, subscribeCallback); | TYPE_CLEARLY | DoNotDisturbType | 以设置时间段(明确年月日时分)执行勿扰。 | - -## EnabledNotificationCallbackData - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| ------ | ---- | --- | ------- | ---- | ---------------- | -| bundle | 是 | 否 | string | 否 | 应用的包名。 | -| uid | 是 | 否 | number | 否 | 应用的uid。 | -| enable | 是 | 否 | boolean | 否 | 应用通知使能状态。 | - - - -## NotificationRequest - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| --------------------- | ---- | --- | --------------------------------------------- | ---- | -------------------------- | -| content | 是 | 是 | [NotificationContent](#notificationcontent) | 是 | 通知内容。 | -| id | 是 | 是 | number | 否 | 通知ID。 | -| slotType | 是 | 是 | [SlotType](#slottype) | 否 | 通道类型。 | -| isOngoing | 是 | 是 | boolean | 否 | 是否进行时通知。 | -| isUnremovable | 是 | 是 | boolean | 否 | 是否可移除。 | -| deliveryTime | 是 | 是 | number | 否 | 通知发送时间。 | -| tapDismissed | 是 | 是 | boolean | 否 | 通知是否自动清除。 | -| autoDeletedTime | 是 | 是 | number | 否 | 自动清除的时间。 | -| wantAgent | 是 | 是 | WantAgent | 否 | 点击跳转的WantAgent。 | -| extraInfo | 是 | 是 | {[key: string]: any} | 否 | 扩展参数。 | -| color | 是 | 是 | number | 否 | 通知背景颜色。 | -| colorEnabled | 是 | 是 | boolean | 否 | 通知背景颜色是否使能。 | -| isAlertOnce | 是 | 是 | boolean | 否 | 设置是否仅有一次此通知警报。 | -| isStopwatch | 是 | 是 | boolean | 否 | 是否显示已用时间。 | -| isCountDown | 是 | 是 | boolean | 否 | 是否显示倒计时时间。 | -| isFloatingIcon | 是 | 是 | boolean | 否 | 是否显示状态栏图标。 | -| label | 是 | 是 | string | 否 | 通知标签。 | -| badgeIconStyle | 是 | 是 | number | 否 | 通知角标类型。 | -| showDeliveryTime | 是 | 是 | boolean | 否 | 是否显示分发时间。 | -| actionButtons | 是 | 是 | Array\<[NotificationActionButton](#notificationactionbutton)\> | 否 | 通知按钮,最多两个按钮。 | -| smallIcon | 是 | 是 | PixelMap | 否 | 通知小图标。 | -| largeIcon | 是 | 是 | PixelMap | 否 | 通知大图标。 | -| creatorBundleName | 是 | 否 | string | 否 | 创建通知的包名。 | -| creatorUid | 是 | 否 | number | 否 | 创建通知的UID。 | -| creatorPid | 是 | 否 | number | 否 | 创建通知的PID。 | -| hashCode | 是 | 否 | string | 否 | 通知唯一标识。 | -| classification | 是 | 是 | string | 否 | 通知分类。 | -| groupName | 是 | 是 | string | 否 | 组通知名称。 | -| template8+ | 是 | 是 | [NotificationTemplate](#notificationtemplate) | 否 | 通知模板。 | - - - -## NotificationSlot - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| -------------------- | ---- | --- | --------------------- | ---- | ------------------------------------------ | -| type | 是 | 是 | [SlotType](#slottype) | 是 | 通道类型。 | -| level | 是 | 是 | number | 否 | 通知级别,不设置则根据通知渠道类型有默认值。 | -| desc | 是 | 是 | string | 否 | 通知渠道描述信息。 | -| badgeFlag | 是 | 是 | boolean | 否 | 是否显示角标。 | -| bypassDnd | 是 | 是 | boolean | 否 | 置是否在系统中绕过免打扰模式。 | -| lockscreenVisibility | 是 | 是 | boolean | 否 | 在锁定屏幕上显示通知的模式。 | -| vibrationEnabled | 是 | 是 | boolean | 否 | 是否可振动。 | -| sound | 是 | 是 | string | 否 | 通知提示音。 | -| lightEnabled | 是 | 是 | boolean | 否 | 是否闪灯。 | -| lightColor | 是 | 是 | number | 否 | 通知灯颜色。 | -| vibrationValues | 是 | 是 | Array\ | 否 | 通知振动样式。 | - -## NotificationContent - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| ----------- | ---- | --- | ------------------------------------------------------------ | ---- | ------------------ | -| contentType | 是 | 是 | [ContentType](#contenttype) | 是 | 通知内容类型。 | -| normal | 是 | 是 | [NotificationBasicContent](#notificationbasiccontent) | 否 | 基本类型通知内容。 | -| longText | 是 | 是 | [NotificationLongTextContent](#notificationlongtextcontent) | 否 | 长文本类型通知内容。 | -| multiLine | 是 | 是 | [NotificationMultiLineContent](#notificationmultilinecontent) | 否 | 多行类型通知内容。 | -| picture | 是 | 是 | [NotificationPictureContent](#notificationpicturecontent) | 否 | 图片类型通知内容。 | - - - ## ContentType **系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification @@ -2972,63 +2531,17 @@ Notification.subscribe(subscriber, subscribeCallback); | NOTIFICATION_CONTENT_CONVERSATION | ContentType | 社交类型通知。 | | NOTIFICATION_CONTENT_MULTILINE | ContentType | 多行文本类型通知。 | - - -## NotificationBasicContent +## SlotLevel **系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| -------------- | ---- | ---- | ------ | ---- | ---------------------------------- | -| title | 是 | 是 | string | 是 | 通知标题。 | -| text | 是 | 是 | string | 是 | 通知内容。 | -| additionalText | 是 | 是 | string | 是 | 通知次要内容,是对通知内容的补充。 | - - - -## NotificationLongTextContent - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| -------------- | ---- | --- | ------ | ---- | -------------------------------- | -| title | 是 | 是 | string | 是 | 通知标题。 | -| text | 是 | 是 | string | 是 | 通知内容。 | -| additionalText | 是 | 是 | string | 是 | 通知次要内容,是对通知内容的补充。 | -| longText | 是 | 是 | string | 是 | 通知的长文本。 | -| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 | -| expandedTitle | 是 | 是 | string | 是 | 通知展开时的标题。 | - - - -## NotificationMultiLineContent - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| -------------- | --- | --- | --------------- | ---- | -------------------------------- | -| title | 是 | 是 | string | 是 | 通知标题。 | -| text | 是 | 是 | string | 是 | 通知内容。 | -| additionalText | 是 | 是 | string | 是 | 通知次要内容,是对通知内容的补充。 | -| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 | -| longTitle | 是 | 是 | string | 是 | 通知展开时的标题。 | -| lines | 是 | 是 | Array\ | 是 | 通知的多行文本。 | - - - -## NotificationPictureContent - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| -------------- | ---- | --- | -------------- | ---- | -------------------------------- | -| title | 是 | 是 | string | 是 | 通知标题。 | -| text | 是 | 是 | string | 是 | 通知内容。 | -| additionalText | 是 | 是 | string | 是 | 通知次要内容,是对通知内容的补充。 | -| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 | -| expandedTitle | 是 | 是 | string | 是 | 通知展开时的标题。 | -| picture | 是 | 是 | image.PixelMap | 是 | 通知的图片内容。 | - +| 名称 | 值 | 说明 | +| --------------------------------- | ----------- | ------------------ | +| LEVEL_NONE | 0 | 表示关闭通知功能。 | +| LEVEL_MIN | 1 | 启用通知功能,但通知不启用。 | +| LEVEL_LOW | 2 | 通知和通止功能都启用。 | +| LEVEL_DEFAULT | 3 | 通知和通止功能都启用。 | +| LEVEL_HIGH | 4 | 通知和通止功能都启用。 | ## BundleOption @@ -3052,7 +2565,6 @@ Notification.subscribe(subscriber, subscribeCallback); | label | 是 | 是 | string | 否 | 通知标签。< | - ## SlotType **系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification @@ -3063,75 +2575,4 @@ Notification.subscribe(subscriber, subscribeCallback); | SOCIAL_COMMUNICATION | SlotType | 社交类型。 | | SERVICE_INFORMATION | SlotType | 服务类型。 | | CONTENT_INFORMATION | SlotType | 内容类型。 | -| OTHER_TYPES | SlotType | 其他类型。 | - - - -## NotificationActionButton - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| --------- | --- | ---- | ----------------------------------------------- | ---- | ------------------------- | -| title | 是 | 是 | string | 是 | 按钮标题。 | -| wantAgent | 是 | 是 | WantAgent | 是 | 点击按钮时触发的WantAgent。 | -| extras | 是 | 是 | Array\ | 否 | 按钮扩展信息。 | -| userInput | 是 | 是 | [NotificationUserInput](#notificationuserinput) | 否 | 用户输入对象实例。 | - - - -## NotificationUserInput - -**系统能力**:SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| -------- | --- | ---- | ------ | ---- | ----------------------------- | -| inputKey | 是 | 是 | string | 是 | 用户输入时用于标识此输入的key。 | - - - -## NotificationSubscribeInfo - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | -| ----------- | --- | ---- | --------------- | ---- | ------------------------------- | -| bundleNames | 是 | 是 | Array\ | 否 | 指定订阅哪些包名的APP发来的通知。 | -| userId | 是 | 是 | number | 否 | 指定订阅哪个用户下发来的通知。 | - - - -## NotificationTemplate - -模板信息 - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| ---- | ---------------------- | ---- | ---- | ---------- | -| name | string | 是 | 是 | 模板名称。 | -| data | {[key:string]: Object} | 是 | 是 | 模板数据。 | - - - -## ActionResult - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| ------------ | ---------- | ---- | ---- | -------- | -| bundleName | string | 是 | 是 | 点击通知后重定向应用的包名。 | -| abilityName | string | 是 | 是 | 点击通知后重定向应用的的Ability名称。 | -| uri | string | 是 | 是 | 要重定向到的页面的Uri。 | - - - -## ShowNotificationOptions - -**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| ------------ | ---------- | ---- | ---- | -------- | -| contentTitle | string | 是 | 是 | 通知的标题。 | -| contentText | string | 是 | 是 | 通知的内容。 | -| clickAction | ActionResult | 是 | 是 | 点击通知后触发的动作。 | +| OTHER_TYPES | SlotType | 其他类型。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationActionButton.md b/zh-cn/application-dev/reference/apis/js-apis-notificationActionButton.md new file mode 100644 index 0000000000000000000000000000000000000000..246098c30366a0283d32de4d6b6ba064836f7de6 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationActionButton.md @@ -0,0 +1,15 @@ +# 在通知中显示的操作按钮。 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationActionButton + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| --------- | --- | ---- | ----------------------------------------------- | ---- | ------------------------- | +| title | 是 | 是 | string | 是 | 按钮标题。 | +| wantAgent | 是 | 是 | WantAgent | 是 | 点击按钮时触发的WantAgent。 | +| extras | 是 | 是 | { [key: string]: any } | 否 | 按钮扩展信息。 | +| userInput\9+ | 是 | 是 | [NotificationUserInput](#notificationuserinput) | 否 | 用户输入对象实例。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationContent.md b/zh-cn/application-dev/reference/apis/js-apis-notificationContent.md new file mode 100644 index 0000000000000000000000000000000000000000..57a6c4988b743e9993d8852649e5e5d4e425bfbc --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationContent.md @@ -0,0 +1,69 @@ +# 通知内容。 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationBasicContent + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| -------------- | ---- | ---- | ------ | ---- | ---------------------------------- | +| title | 是 | 是 | string | 是 | 通知标题。 | +| text | 是 | 是 | string | 是 | 通知内容。 | +| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 | + + +## NotificationLongTextContent + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| -------------- | ---- | --- | ------ | ---- | -------------------------------- | +| title | 是 | 是 | string | 是 | 通知标题。 | +| text | 是 | 是 | string | 是 | 通知内容。 | +| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 | +| longText | 是 | 是 | string | 是 | 通知的长文本。 | +| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 | +| expandedTitle | 是 | 是 | string | 是 | 通知展开时的标题。 | + + +## NotificationMultiLineContent + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| -------------- | --- | --- | --------------- | ---- | -------------------------------- | +| title | 是 | 是 | string | 是 | 通知标题。 | +| text | 是 | 是 | string | 是 | 通知内容。 | +| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 | +| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 | +| longTitle | 是 | 是 | string | 是 | 通知展开时的标题。 | +| lines | 是 | 是 | Array\ | 是 | 通知的多行文本。 | + + +## NotificationPictureContent + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| -------------- | ---- | --- | -------------- | ---- | -------------------------------- | +| title | 是 | 是 | string | 是 | 通知标题。 | +| text | 是 | 是 | string | 是 | 通知内容。 | +| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 | +| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 | +| expandedTitle | 是 | 是 | string | 是 | 通知展开时的标题。 | +| picture | 是 | 是 | image.PixelMap | 是 | 通知的图片内容。 | + + +## NotificationContent + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| ----------- | ---- | --- | ------------------------------------------------------------ | ---- | ------------------ | +| contentType | 是 | 是 | [ContentType](#contenttype) | 是 | 通知内容类型。 | +| normal | 是 | 是 | [NotificationBasicContent](#notificationbasiccontent) | 否 | 基本类型通知内容。 | +| longText | 是 | 是 | [NotificationLongTextContent](#notificationlongtextcontent) | 否 | 长文本类型通知内容。 | +| multiLine | 是 | 是 | [NotificationMultiLineContent](#notificationmultilinecontent) | 否 | 多行类型通知内容。 | +| picture | 是 | 是 | [NotificationPictureContent](#notificationpicturecontent) | 否 | 图片类型通知内容。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationFlags.md b/zh-cn/application-dev/reference/apis/js-apis-notificationFlags.md new file mode 100644 index 0000000000000000000000000000000000000000..847757f753b58327aa054f220778dbffc352a1e1 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationFlags.md @@ -0,0 +1,28 @@ +# 通知标志。 + +> **说明:** +> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationFlagStatus + +通知标志的状态。 + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 值 | 描述 | +| -------------- | --- | --------------------------------- | +| TYPE_NONE | 0 | 默认标志。 | +| TYPE_OPEN | 1 | 通知标志打开。 | +| TYPE_CLOSE | 2 | 通知标志打开。 | + + +## NotificationFlags + +NotificationFlags实例。 + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| ---------------- | ---- | ---- | ---------------------- | ---- | --------------------------------- | +| soundEnabled | 是 | 否 | NotificationFlagStatus | 否 | 是否启用声音提示。 | +| vibrationEnabled | 是 | 否 | NotificationFlagStatus | 否 | 是否启用振动提醒功能。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationRequest.md b/zh-cn/application-dev/reference/apis/js-apis-notificationRequest.md new file mode 100644 index 0000000000000000000000000000000000000000..21a7999c4880b24bb8b848069b58bc0fee93365f --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationRequest.md @@ -0,0 +1,58 @@ +# NotificationRequest实例。 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationRequest + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| --------------------- | ---- | --- | --------------------------------------------- | ---- | -------------------------- | +| content | 是 | 是 | [NotificationContent](#notificationcontent) | 是 | 通知内容。 | +| id | 是 | 是 | number | 否 | 通知ID。 | +| slotType | 是 | 是 | [SlotType](#slottype) | 否 | 通道类型。 | +| isOngoing | 是 | 是 | boolean | 否 | 是否进行时通知。 | +| isUnremovable | 是 | 是 | boolean | 否 | 是否可移除。 | +| deliveryTime | 是 | 是 | number | 否 | 通知发送时间。 | +| tapDismissed | 是 | 是 | boolean | 否 | 通知是否自动清除。 | +| autoDeletedTime | 是 | 是 | number | 否 | 自动清除的时间。 | +| wantAgent | 是 | 是 | WantAgent | 否 | 点击跳转的WantAgent。 | +| extraInfo | 是 | 是 | {[key: string]: any} | 否 | 扩展参数。 | +| color | 是 | 是 | number | 否 | 通知背景颜色。 | +| colorEnabled | 是 | 是 | boolean | 否 | 通知背景颜色是否使能。 | +| isAlertOnce | 是 | 是 | boolean | 否 | 设置是否仅有一次此通知警报。 | +| isStopwatch | 是 | 是 | boolean | 否 | 是否显示已用时间。 | +| isCountDown | 是 | 是 | boolean | 否 | 是否显示倒计时时间。 | +| isFloatingIcon | 是 | 是 | boolean | 否 | 是否显示状态栏图标。 | +| label | 是 | 是 | string | 否 | 通知标签。 | +| badgeIconStyle | 是 | 是 | number | 否 | 通知角标类型。 | +| showDeliveryTime | 是 | 是 | boolean | 否 | 是否显示分发时间。 | +| actionButtons | 是 | 是 | Array\<[NotificationActionButton](#notificationactionbutton)\> | 否 | 通知按钮,最多两个按钮。 | +| smallIcon | 是 | 是 | PixelMap | 否 | 通知小图标。 | +| largeIcon | 是 | 是 | PixelMap | 否 | 通知大图标。 | +| creatorBundleName | 是 | 否 | string | 否 | 创建通知的包名。 | +| creatorUid | 是 | 否 | number | 否 | 创建通知的UID。 | +| creatorPid | 是 | 否 | number | 否 | 创建通知的PID。 | +| creatorUserId8+| 是 | 否 | number | 否 | 创建通知的UserId。 | +| hashCode | 是 | 否 | string | 否 | 通知唯一标识。 | +| classification | 是 | 是 | string | 否 | 通知分类。 | +| groupName8+| 是 | 是 | string | 否 | 组通知名称。 | +| template8+ | 是 | 是 | [NotificationTemplate](#notificationtemplate) | 否 | 通知模板。 | +| isRemoveAllowed8+ | 是 | 否 | boolean | 否 | 通知是否能被移除。 | +| source8+ | 是 | 否 | number | 否 | 通知源。 | +| distributedOption8+ | 是 | 是 | DistributedOptions | 否 | 分布式通知的选项。 | +| deviceId8+ | 是 | 否 | string | 否 | 通知源的deviceId。 | +| notificationFlags8+ | 是 | 否 | NotificationFlags | 否 | 获取NotificationFlags。 | + + +## DistributedOptions8+ + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| ---------------------- | ---- | ---- | -------------- | ---- | ---------------------------------- | +| isDistributed | 是 | 是 | boolean | 否 | 是否为分布式通知。 | +| supportDisplayDevices | 是 | 是 | Array\ | 是 | 可以同步通知到的设备类型。 | +| supportOperateDevices | 是 | 是 | Array\ | 否 | 可以打开通知的设备。 | +| remindType | 是 | 否 | number | 否 | 通知的提醒方式。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationSlot.md b/zh-cn/application-dev/reference/apis/js-apis-notificationSlot.md new file mode 100644 index 0000000000000000000000000000000000000000..5b737efbf9f2971b2c4e473605ab0b67e8ca5979 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationSlot.md @@ -0,0 +1,23 @@ +# NotificationSlot实例。 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + + +## NotificationSlot + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| -------------------- | ---- | --- | --------------------- | ---- | ------------------------------------------ | +| type | 是 | 是 | [SlotType](#slottype) | 是 | 通道类型。 | +| level | 是 | 是 | number | 否 | 通知级别,不设置则根据通知渠道类型有默认值。 | +| desc | 是 | 是 | string | 否 | 通知渠道描述信息。 | +| badgeFlag | 是 | 是 | boolean | 否 | 是否显示角标。 | +| bypassDnd | 是 | 是 | boolean | 否 | 置是否在系统中绕过免打扰模式。 | +| lockscreenVisibility | 是 | 是 | boolean | 否 | 在锁定屏幕上显示通知的模式。 | +| vibrationEnabled | 是 | 是 | boolean | 否 | 是否可振动。 | +| sound | 是 | 是 | string | 否 | 通知提示音。 | +| lightEnabled | 是 | 是 | boolean | 否 | 是否闪灯。 | +| lightColor | 是 | 是 | number | 否 | 通知灯颜色。 | +| vibrationValues | 是 | 是 | Array\ | 否 | 通知振动样式。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationSorting.md b/zh-cn/application-dev/reference/apis/js-apis-notificationSorting.md new file mode 100644 index 0000000000000000000000000000000000000000..7d34bd3788b3d99115be14e17aa53ceed34842d5 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationSorting.md @@ -0,0 +1,14 @@ +# 一个活跃通知的排序信息。 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationSorting + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| -------- | ---- | --- | ------------------------------------- | ---- | ------------ | +| slot | 是 | 否 | [NotificationSlot](#notificationslot) | 是 | 通知通道内容。 | +| hashCode | 是 | 否 | string | 是 | 通知唯一标识。 | +| ranking | 是 | 否 | number | 是 | 通知排序序号。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationSortingMap.md b/zh-cn/application-dev/reference/apis/js-apis-notificationSortingMap.md new file mode 100644 index 0000000000000000000000000000000000000000..ada4f23211c20009db760c46c45ccb1ba3445221 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationSortingMap.md @@ -0,0 +1,13 @@ +# 关于已订阅的所有通知中的活动通知的排序信息 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationSortingMap + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| -------------- | ---- | --- | ------------------------------------------------------------ | ---- | ---------------- | +| sortings | 是 | 否 | {[key: string]: [NotificationSorting](#notificationsorting)} | 是 | 通知排序信息数组。 | +| sortedHashCode | 是 | 否 | Array\ | 是 | 通知唯一标识数组。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationSubscribeInfo.md b/zh-cn/application-dev/reference/apis/js-apis-notificationSubscribeInfo.md new file mode 100644 index 0000000000000000000000000000000000000000..0e9cedffb5cd6bc51a5848be853644537240f4da --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationSubscribeInfo.md @@ -0,0 +1,14 @@ +# 设置发布者订阅所需通知的过滤条件。 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + + +## NotificationSubscribeInfo + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| ----------- | --- | ---- | --------------- | ---- | ------------------------------- | +| bundleNames | 是 | 是 | Array\ | 否 | 指定订阅哪些包名的APP发来的通知。 | +| userId | 是 | 是 | number | 否 | 指定订阅哪个用户下发来的通知。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationSubscriber.md b/zh-cn/application-dev/reference/apis/js-apis-notificationSubscriber.md new file mode 100644 index 0000000000000000000000000000000000000000..01a8ad8549a5f780c5d9d8c69eb3368b86191bc9 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationSubscriber.md @@ -0,0 +1,317 @@ +# 提供在订阅者收到新通知或取消通知时将回调的方法。 + +> **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationSubscriber +### onConsume + +onConsume?:(data: [SubscribeCallbackData](#subscribecallbackdata)) + +接收通知回调函数。 + +**系统能力**:SystemCapability.Notification.Notification + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ------------------------ | ---- | -------------------------- | +| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | 是 | 回调返回接收到的通知信息。 | + +**示例:** + +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onConsumeCallback(data) { + console.info('===> onConsume in test'); + let req = data.request; + console.info('===> onConsume callback req.id:' + req.id); + let wantAgent = data.wantAgent; + wantAgent .getWant(wantAgent) + .then((data1) => { + console.log('===> getWant success want:' + JSON.stringfy(data1)); + }) + .catch((err) => { + console.error('===> getWant failed because' + JSON.stringfy(err)); + }); + console.info('===> onConsume callback req.wantAgent:' + JSON.stringfy(req.wantAgent)); +}; + +var subscriber = { + onConsume: onConsumeCallback +}; + +Notification.subscribe(subscriber, subscribeCallback); +``` + +### onCancel + +onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) + +删除通知回调函数。 + +**系统能力**:SystemCapability.Notification.Notification + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ------------------------ | ---- | -------------------------- | +| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | 是 | 回调返回接收到的通知信息。 | + +**示例:** + +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onCancelCallback(data) { + console.info('===> onCancel in test'); + let req = data.request; + console.info('===> onCancel callback req.id:' + req.id); +} + +var subscriber = { + onCancel: onCancelCallback +}; + +Notification.subscribe(subscriber, subscribeCallback); +``` + +### onUpdate + +onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap)) + +更新通知排序回调函数。 + +**系统能力**:SystemCapability.Notification.Notification + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ------------------------ | ---- | -------------------------- | +| data | [NotificationSortingMap](#notificationsortingmap) | 是 | | + +**示例:** + +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onUpdateCallback() { + console.info('===> onUpdate in test'); +} + +var subscriber = { + onUpdate: onUpdateCallback +}; + +Notification.subscribe(subscriber, subscribeCallback); +``` + +### onConnect + +onConnect?:void + +注册订阅回调函数。 + +**系统能力**:SystemCapability.Notification.Notification + +**示例:** + +```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'); +} + +var subscriber = { + onConnect: onConnectCallback +}; + +Notification.subscribe(subscriber, subscribeCallback); +``` + +### onDisconnect + +onDisconnect?:void + +取消订阅回调函数。 + +**系统能力**:SystemCapability.Notification.Notification + +**示例:** + +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onDisconnectCallback() { + console.info('===> onDisconnect in test'); +} + +var subscriber = { + onDisconnect: onDisconnectCallback +}; + +Notification.subscribe(subscriber, subscribeCallback); +``` + +### onDestroy + +onDestroy?:void + +服务失联回调函数。 + +**系统能力**:SystemCapability.Notification.Notification + +**示例:** + +```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'); +} + +var subscriber = { + onDestroy: onDestroyCallback +}; + +Notification.subscribe(subscriber, subscribeCallback); +``` + +### onDoNotDisturbDateChange8+ + +onDoNotDisturbDateChange?:(mode: Notification.[DoNotDisturbDate](#donotdisturbdate)) + +免打扰时间选项变更回调函数。 + +**系统能力**:SystemCapability.Notification.Notification + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ------------------------ | ---- | -------------------------- | +| mode | Notification.[DoNotDisturbDate](#donotdisturbdate) | 是 | 回调返回免打扰时间选项变更。 | + +**示例:** +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onDoNotDisturbDateChangeCallback() { + console.info('===> onDoNotDisturbDateChange in test'); +} + +var subscriber = { + onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback +}; + +Notification.subscribe(subscriber, subscribeCallback); +``` + + +### onEnabledNotificationChanged8+ + +onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata)) + +监听应用通知使能变化。 + +**系统能力**:SystemCapability.Notification.Notification + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata)\> | 是 | 回调返回监听到的应用信息。 | + +**示例:** + +```javascript +function subscribeCallback(err) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onEnabledNotificationChangedCallback(err, callbackData) { + if (err.code) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("bundle: ", callbackData.bundle); + console.info("uid: ", callbackData.uid); + console.info("enable: ", callbackData.enable); + } +}; + +var subscriber = { + onEnabledNotificationChanged: onEnabledNotificationChangedCallback +}; + +Notification.subscribe(subscriber, subscribeCallback); +``` + +## SubscribeCallbackData + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| --------------- | ---- | --- | ------------------------------------------------- | ---- | -------- | +| request | 是 | 否 | [NotificationRequest](#notificationrequest) | 是 | 通知内容。 | +| sortingMap | 是 | 否 | [NotificationSortingMap](#notificationsortingmap) | 否 | 排序信息。 | +| reason | 是 | 否 | number | 否 | 删除原因。 | +| sound | 是 | 否 | string | 否 | 通知声音。 | +| vibrationValues | 是 | 否 | Array\ | 否 | 通知震动。 | + + +## EnabledNotificationCallbackData8+ + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| ------ | ---- | --- | ------- | ---- | ---------------- | +| bundle | 是 | 否 | string | 是 | 应用的包名。 | +| uid | 是 | 否 | number | 是 | 应用的uid。 | +| enable | 是 | 否 | boolean | 是 | 应用通知使能状态。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationTemplate.md b/zh-cn/application-dev/reference/apis/js-apis-notificationTemplate.md new file mode 100644 index 0000000000000000000000000000000000000000..528da05aed0114bbece5f3b79114d5d00878babf --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationTemplate.md @@ -0,0 +1,15 @@ +# NotificationTemplate实例。 + +> **说明:** +> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationTemplate + +模板信息 + +**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| ---- | ---------------------- | ---- | ---- | ---------- | +| name | string | 是 | 是 | 模板名称。 | +| data | {[key:string]: Object} | 是 | 是 | 模板数据。 | \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationUserInput.md b/zh-cn/application-dev/reference/apis/js-apis-notificationUserInput.md new file mode 100644 index 0000000000000000000000000000000000000000..555180386624c7542d2fd385ac7f625d29faa9dd --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationUserInput.md @@ -0,0 +1,12 @@ +# NotificationUserInput实例。 + +> **说明:** +> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## NotificationUserInput + +**系统能力**:SystemCapability.Notification.Notification + +| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | +| -------- | --- | ---- | ------ | ---- | ----------------------------- | +| inputKey | 是 | 是 | string | 是 | 用户输入时用于标识此输入的key。 | \ No newline at end of file