提交 a5017c30 编写于 作者: Z zhaoyuan17

Update js api notification interface

Signed-off-by: Nzhaoyuan17 <zhaoyuan17@huawei.com>
上级 b5571296
# Notification模块(JS端SDK接口) # Notification模块(JS端SDK接口)
#### 支持设备 #### 支持设备
| API | 手机 | 平板 | 智慧屏 | 智能穿戴 | | API | 手机 | 平板 | 智慧屏 | 智能穿戴 |
| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | | ------------------------------------------------------------ | ---- | ---- | ------ | -------- |
| Notification.publish(request: NotificationRequest, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.publish(request: NotificationRequest, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.publish(request: NotificationRequest) | 支持 | 支持 | 支持 | 支持 | | Notification.publish(request: NotificationRequest) | 支持 | 支持 | 支持 | 支持 |
| Notification.cancel(id: number, label: string, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.cancel(id: number, label: string, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.cancel(id:number, label?:string) | 支持 | 支持 | 支持 | 支持 | | Notification.cancel(id:number, label?:string) | 支持 | 支持 | 支持 | 支持 |
| Notification.cancel(id: number, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.cancel(id: number, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.cancelAll(callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.cancelAll(callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.cancelAll() | 支持 | 支持 | 支持 | 支持 | | Notification.cancelAll() | 支持 | 支持 | 支持 | 支持 |
| Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.addSlot(slot: NotificationSlot) | 支持 | 支持 | 支持 | 支持 | | Notification.addSlot(slot: NotificationSlot) | 支持 | 支持 | 支持 | 支持 |
| Notification.addSlot(type: SlotType, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.addSlot(type: SlotType, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.addSlot(type: SlotType) | 支持 | 支持 | 支持 | 支持 | | Notification.addSlot(type: SlotType) | 支持 | 支持 | 支持 | 支持 |
| Notification.addSlots(slots: Array<NotificationSlot>, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.addSlots(slots: Array<NotificationSlot>) | 支持 | 支持 | 支持 | 支持 | | Notification.addSlots(slots: Array\<NotificationSlot\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.getSlot(slotType: SlotType, callback: AsyncCallback<NotificationSlot>) | 支持 | 支持 | 支持 | 支持 | | Notification.getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.getSlot(slotType: SlotType) | 支持 | 支持 | 支持 | 支持 | | Notification.getSlot(slotType: SlotType) | 支持 | 支持 | 支持 | 支持 |
| Notification.getSlots(callback: AsyncCallback<Array<NotificationSlot>>) | 支持 | 支持 | 支持 | 支持 | | Notification.getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>) | 支持 | 支持 | 支持 | 支持 |
| Notification.getSlots() | 支持 | 支持 | 支持 | 支持 | | Notification.getSlots() | 支持 | 支持 | 支持 | 支持 |
| Notification.removeSlot(slotType: SlotType, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.removeSlot(slotType: SlotType) | 支持 | 支持 | 支持 | 支持 | | Notification.removeSlot(slotType: SlotType) | 支持 | 支持 | 支持 | 支持 |
| Notification.removeAllSlots(callback: AsyncCallback<void>): void | 支持 | 支持 | 支持 | 支持 | | Notification.removeAllSlots(callback: AsyncCallback\<void\>): void | 支持 | 支持 | 支持 | 支持 |
| Notification.removeAllSlots(): Promise<void> | 支持 | 支持 | 支持 | 支持 | | Notification.removeAllSlots(): Promise\<void\> | 支持 | 支持 | 支持 | 支持 |
| Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) | 支持 | 支持 | 支持 | 支持 | | Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) | 支持 | 支持 | 支持 | 支持 |
| Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.unsubscribe(subscriber: NotificationSubscriber) | 支持 | 支持 | 支持 | 支持 | | Notification.unsubscribe(subscriber: NotificationSubscriber) | 支持 | 支持 | 支持 | 支持 |
| Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.enableNotification(bundle: BundleOption, enable: boolean) | 支持 | 支持 | 支持 | 支持 | | Notification.enableNotification(bundle: BundleOption, enable: boolean) | 支持 | 支持 | 支持 | 支持 |
| Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback<boolean>) | 支持 | 支持 | 支持 | 支持 | | Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.isNotificationEnabled(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 | | Notification.isNotificationEnabled(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 |
| Notification.isNotificationEnabled(callback: AsyncCallback<boolean>) | 支持 | 支持 | 支持 | 支持 | | Notification.isNotificationEnabled(callback: AsyncCallback\<boolean\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.isNotificationEnabled() | 支持 | 支持 | 支持 | 支持 | | Notification.isNotificationEnabled() | 支持 | 支持 | 支持 | 支持 |
| Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.displayBadge(bundle: BundleOption, enable: boolean) | 支持 | 支持 | 支持 | 支持 | | Notification.displayBadge(bundle: BundleOption, enable: boolean) | 支持 | 支持 | 支持 | 支持 |
| Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback<boolean>) | 支持 | 支持 | 支持 | 支持 | | Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.isBadgeDisplayed(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 | | Notification.isBadgeDisplayed(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 |
| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) | 支持 | 支持 | 支持 | 支持 | | Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) | 支持 | 支持 | 支持 | 支持 |
| Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array<NotificationSlot>>) | 支持 | 支持 | 支持 | 支持 | | Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>) | 支持 | 支持 | 支持 | 支持 |
| Notification.getSlotsByBundle(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 | | Notification.getSlotsByBundle(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 |
| Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback<number>) | 支持 | 支持 | 支持 | 支持 | | Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.getSlotNumByBundle(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 | | Notification.getSlotNumByBundle(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 |
| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) | 支持 | 支持 | 支持 | 支持 | | Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) | 支持 | 支持 | 支持 | 支持 |
| Notification.remove(hashCode: string, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.remove(hashCode: string, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.remove(hashCode: string) | 支持 | 支持 | 支持 | 支持 | | Notification.remove(hashCode: string) | 支持 | 支持 | 支持 | 支持 |
| Notification.removeAll(bundle: BundleOption, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.removeAll(callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.removeAll(callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.removeAll(bundle?: BundleOption) | 支持 | 支持 | 支持 | 支持 | | Notification.removeAll(bundle?: BundleOption) | 支持 | 支持 | 支持 | 支持 |
| Notification.getAllActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>) | 支持 | 支持 | 支持 | 支持 | | Notification.getAllActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>) | 支持 | 支持 | 支持 | 支持 |
| Notification.getAllActiveNotifications() | 支持 | 支持 | 支持 | 支持 | | Notification.getAllActiveNotifications() | 支持 | 支持 | 支持 | 支持 |
| Notification.getActiveNotificationCount(callback: AsyncCallback<number>) | 支持 | 支持 | 支持 | 支持 | | Notification.getActiveNotificationCount(callback: AsyncCallback\<number\>) | 支持 | 支持 | 支持 | 支持 |
| Notification.getActiveNotificationCount() | 支持 | 支持 | 支持 | 支持 | | Notification.getActiveNotificationCount() | 支持 | 支持 | 支持 | 支持 |
| Notification.getActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>) | 支持 | 支持 | 支持 | 支持 | | Notification.getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>) | 支持 | 支持 | 支持 | 支持 |
| Notification.getActiveNotifications() | 支持 | 支持 | 支持 | 支持 | | Notification.getActiveNotifications() | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>) | 支持 | 支持 | 支持 | 支持 | | Notification.cancelGroup(groupName: string, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getWantAgent(info: WantAgentInfo): Promise<WantAgent> | 支持 | 支持 | 支持 | 支持 | | Notification.cancelGroup(groupName: string) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback<string>) | 支持 | 支持 | 支持 | 支持 | | Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getBundleName(agent: WantAgent): Promise<string> | 支持 | 支持 | 支持 | 支持 | | Notification.removeGroupByBundle(bundle: BundleOption, groupName: string) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getUid(agent: WantAgent, callback: AsyncCallback<number>) | 支持 | 支持 | 支持 | 支持 | | Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getUid(agent: WantAgent): Promise<number> | 支持 | 支持 | 支持 | 支持 | | Notification.setDoNotDisturbDate(date: DoNotDisturbDate) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getWant(agent: WantAgent, callback: AsyncCallback<Want>) | 支持 | 支持 | 支持 | 支持 | | Notification.getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getWant(agent: WantAgent): Promise<Want> | 支持 | 支持 | 支持 | 支持 | | Notification.getDoNotDisturbDate() | 支持 | 支持 | 支持 | 支持 |
| WantAgent.cancel(agent: WantAgent, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | | Notification.supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.cancel(agent: WantAgent): Promise<void> | 支持 | 支持 | 支持 | 支持 | | Notification.supportDoNotDisturbMode() | 支持 | 支持 | 支持 | 支持 |
| WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>) | 支持 | 支持 | 支持 | 支持 | | WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>) | 支持 | 支持 | 支持 | 支持 | | WantAgent.getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> | 支持 | 支持 | 支持 | 支持 |
| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise<boolean> | 支持 | 支持 | 支持 | 支持 | | WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getBundleName(agent: WantAgent): Promise\<string\> | 支持 | 支持 | 支持 | 支持 |
#### 权限列表 | WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\<number\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getUid(agent: WantAgent): Promise\<number\> | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\<Want\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.getWant(agent: WantAgent): Promise\<Want\> | 支持 | 支持 | 支持 | 支持 |
#### 通知接口 | WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\<void\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.cancel(agent: WantAgent): Promise\<void\> | 支持 | 支持 | 支持 | 支持 |
#### 导入模块 | WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>) | 支持 | 支持 | 支持 | 支持 |
| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>) | 支持 | 支持 | 支持 | 支持 |
```js | WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\> | 支持 | 支持 | 支持 | 支持 |
import notify from '@ohos.notification';
``` #### 权限列表
#### Notification.publish(request: NotificationRequest, callback: AsyncCallback<void>)
- 接口说明 #### 通知接口
发布通知(callback形式) #### 导入模块
- publish参数描述 ```js
import notify from '@ohos.notification';
```
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ------------------- | ---- | ------------------------------------------- | #### Notification.publish(request: NotificationRequest, callback: AsyncCallback\<void\>)
| request | 只读 | NotificationRequest | 是 | 设置要发布通知内容的NotificationRequest对象 |
| callback | 只读 | AsyncCallback<void> | 是 | 被指定的回调方法 | - 接口说明
- NotificationRequest类型说明 发布通知(callback形式)
| 名称 | 读写属性 | 类型 | 必填 | 描述 | - publish参数描述
| ----------------- | -------- | ------------------------------- | ---- | -------------------------- |
| content | 读、写 | NotificationContent | 是 | 通知内容 |
| id | 读、写 | number | 否 | 通知ID | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| slotType | 读、写 | SlotType | 否 | 通道类型 | | -------- | -------- | --------------------- | ---- | ------------------------------------------- |
| isOngoing | 读、写 | boolean | 否 | 是否进行时通知 | | request | 只读 | NotificationRequest | 是 | 设置要发布通知内容的NotificationRequest对象 |
| isUnremovable | 读、写 | boolean | 否 | 是否可移除 | | callback | 只读 | AsyncCallback\<void\> | 是 | 被指定的回调方法 |
| deliveryTime | 读、写 | number | 否 | 通知发送时间 |
| tapDismissed | 读、写 | boolean | 否 | 通知是否自动清除 | - NotificationRequest类型说明
| autoDeletedTime | 读、写 | number | 否 | 自动清除的时间 |
| wantAgent | 读、写 | WantAgent | 否 | 点击跳转的WantAgent | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| extraInfo | 读、写 | {[key: string]: any} | 否 | 扩展参数 | | ----------------- | -------- | --------------------------------- | ---- | -------------------------- |
| color | 读、写 | number | 否 | 通知背景颜色 | | content | 读、写 | NotificationContent | 是 | 通知内容 |
| colorEnabled | 读、写 | boolean | 否 | 通知背景颜色是否使能 | | id | 读、写 | number | 否 | 通知ID |
| isAlertOnce | 读、写 | boolean | 否 | 设置是否仅有一次此通知警报 | | slotType | 读、写 | SlotType | 否 | 通道类型 |
| isStopwatch | 读、写 | boolean | 否 | 是否显示已用时间 | | isOngoing | 读、写 | boolean | 否 | 是否进行时通知 |
| isCountDown | 读、写 | boolean | 否 | 是否显示倒计时时间 | | isUnremovable | 读、写 | boolean | 否 | 是否可移除 |
| isFloatingIcon | 读、写 | boolean | 否 | 是否显示状态栏图标 | | deliveryTime | 读、写 | number | 否 | 通知发送时间 |
| isFloatingIcon | 读、写 | boolean | 否 | 是否显示状态栏图标 | | tapDismissed | 读、写 | boolean | 否 | 通知是否自动清除 |
| label | 读、写 | string | 否 | 通知标签 | | autoDeletedTime | 读、写 | number | 否 | 自动清除的时间 |
| badgeIconStyle | 读、写 | number | 否 | 通知角标类型 | | wantAgent | 读、写 | WantAgent | 否 | 点击跳转的WantAgent |
| showDeliveryTime | 读、写 | boolean | 否 | 是否显示分发时间 | | extraInfo | 读、写 | {[key: string]: any} | 否 | 扩展参数 |
| actionButtons | 读、写 | Array<NotificationActionButton> | 否 | 通知按钮,最多两个按钮 | | color | 读、写 | number | 否 | 通知背景颜色 |
| smallIcon | 读、写 | PixelMap | 否 | 通知小图标 | | colorEnabled | 读、写 | boolean | 否 | 通知背景颜色是否使能 |
| largeIcon | 读、写 | PixelMap | 否 | 通知大图标 | | isAlertOnce | 读、写 | boolean | 否 | 设置是否仅有一次此通知警报 |
| creatorBundleName | 只读 | string | 否 | 创建通知的包名 | | isStopwatch | 读、写 | boolean | 否 | 是否显示已用时间 |
| creatorUid | 只读 | number | 否 | 创建通知的UID | | isCountDown | 读、写 | boolean | 否 | 是否显示倒计时时间 |
| creatorPid | 只读 | number | 否 | 创建通知的PID | | isFloatingIcon | 读、写 | boolean | 否 | 是否显示状态栏图标 |
| hashCode | 只读 | string | 否 | 通知唯一标识 | | label | 读、写 | string | 否 | 通知标签 |
| classification | 读、写 | string | 否 | 通知分类 | | badgeIconStyle | 读、写 | number | 否 | 通知角标类型 |
| showDeliveryTime | 读、写 | boolean | 否 | 是否显示分发时间 |
NotificationContent类型说明 | actionButtons | 读、写 | Array\<NotificationActionButton\> | 否 | 通知按钮,最多两个按钮 |
| smallIcon | 读、写 | PixelMap | 否 | 通知小图标 |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | largeIcon | 读、写 | PixelMap | 否 | 通知大图标 |
| ----------- | -------- | ---------------------------- | ---- | -------------- | | creatorBundleName | 只读 | string | 否 | 创建通知的包名 |
| contentType | 读、写 | ContentType | 是 | 通知内容类型 | | creatorUid | 只读 | number | 否 | 创建通知的UID |
| normal | 读、写 | NotificationBasicContent | 否 | 通知基本内容 | | creatorPid | 只读 | number | 否 | 创建通知的PID |
| longText | 读、写 | NotificationLongTextContent | 否 | 通知长文本内容 | | hashCode | 只读 | string | 否 | 通知唯一标识 |
| multiLine | 读、写 | NotificationMultiLineContent | 否 | 通知多行内容 | | classification | 读、写 | string | 否 | 通知分类 |
| groupName | 读、写 | string | 否 | 组通知名称 |
- ContentType类型说明
NotificationContent类型说明
| 名称 | 读写属性 | 类型 | 描述 |
| --------------------------------- | -------- | ----------- | ---------------- | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| NOTIFICATION_CONTENT_BASIC_TEXT | 只读 | ContentType | 普通类型通知 | | ----------- | -------- | ---------------------------- | ---- | -------------- |
| NOTIFICATION_CONTENT_LONG_TEXT | 只读 | ContentType | 长文本类型通知 | | contentType | 读、写 | ContentType | 是 | 通知内容类型 |
| NOTIFICATION_CONTENT_PICTURE | 只读 | ContentType | 图片类型通知 | | normal | 读、写 | NotificationBasicContent | 否 | 通知基本内容 |
| NOTIFICATION_CONTENT_CONVERSATION | 只读 | ContentType | 社交类型通知 | | longText | 读、写 | NotificationLongTextContent | 否 | 通知长文本内容 |
| NOTIFICATION_CONTENT_MULTILINE | 只读 | ContentType | 多行文本类型通知 | | multiLine | 读、写 | NotificationMultiLineContent | 否 | 通知多行内容 |
- NotificationBasicContent类型说明 - ContentType类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 描述 |
| -------------- | -------- | ------ | ---- | -------------------------------- | | --------------------------------- | -------- | ----------- | ---------------- |
| title | 读、写 | string | 是 | 通知标题 | | NOTIFICATION_CONTENT_BASIC_TEXT | 只读 | ContentType | 普通类型通知 |
| text | 读、写 | string | 是 | 通知内容 | | NOTIFICATION_CONTENT_LONG_TEXT | 只读 | ContentType | 长文本类型通知 |
| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | | NOTIFICATION_CONTENT_PICTURE | 只读 | ContentType | 图片类型通知 |
| NOTIFICATION_CONTENT_CONVERSATION | 只读 | ContentType | 社交类型通知 |
- NotificationLongTextContent类型说明 | NOTIFICATION_CONTENT_MULTILINE | 只读 | ContentType | 多行文本类型通知 |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | - NotificationBasicContent类型说明
| -------------- | -------- | ------ | ---- | -------------------------------- |
| title | 读、写 | string | 是 | 通知标题 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| text | 读、写 | string | 是 | 通知内容 | | -------------- | -------- | ------ | ---- | -------------------------------- |
| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | | title | 读、写 | string | 是 | 通知标题 |
| longText | 读、写 | string | 是 | 通知的长文本 | | text | 读、写 | string | 是 | 通知内容 |
| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | | additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 |
| expandedTitle | 读、写 | string | 是 | 通知展开时的标题 |
- NotificationLongTextContent类型说明
- NotificationMultiLineContent类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | -------------- | -------- | ------ | ---- | -------------------------------- |
| -------------- | -------- | ------------- | ---- | -------------------------------- | | title | 读、写 | string | 是 | 通知标题 |
| title | 读、写 | string | 是 | 通知标题 | | text | 读、写 | string | 是 | 通知内容 |
| text | 读、写 | string | 是 | 通知内容 | | additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 |
| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | | longText | 读、写 | string | 是 | 通知的长文本 |
| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | | briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 |
| longTitle | 读、写 | string | 是 | 通知展开时的标题 | | expandedTitle | 读、写 | string | 是 | 通知展开时的标题 |
| lines | 读、写 | Array<String> | 是 | 通知的多行文本 |
- NotificationMultiLineContent类型说明
- NotificationPictureContent类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | -------------- | -------- | --------------- | ---- | -------------------------------- |
| -------------- | -------- | -------------- | ---- | -------------------------------- | | title | 读、写 | string | 是 | 通知标题 |
| title | 读、写 | string | 是 | 通知标题 | | text | 读、写 | string | 是 | 通知内容 |
| text | 读、写 | string | 是 | 通知内容 | | additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 |
| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | | briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 |
| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | | longTitle | 读、写 | string | 是 | 通知展开时的标题 |
| expandedTitle | 读、写 | string | 是 | 通知展开时的标题 | | lines | 读、写 | Array\<String\> | 是 | 通知的多行文本 |
| picture | 读、写 | image.PixelMap | 是 | 通知的图片内容 |
- NotificationPictureContent类型说明
- NotificationActionButton类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | -------------- | -------- | -------------- | ---- | -------------------------------- |
| --------- | -------- | -------------- | ---- | ------------------------- | | title | 读、写 | string | 是 | 通知标题 |
| title | 读、写 | string | 是 | 按钮标题 | | text | 读、写 | string | 是 | 通知内容 |
| wantAgent | 读、写 | wantAgent | 是 | 点击按钮时触发的WantAgent | | additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 |
| extras | 读、写 | Array<String> | 否 | 按钮扩展信息 | | briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 |
| icon | 读、写 | image.PixelMap | 否 | 按钮图标 | | expandedTitle | 读、写 | string | 是 | 通知展开时的标题 |
| picture | 读、写 | image.PixelMap | 是 | 通知的图片内容 |
- 返回值
- NotificationActionButton类型说明
返回值为void
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
- 示例 | --------- | -------- | --------------------- | ---- | ------------------------- |
| title | 读、写 | string | 是 | 按钮标题 |
```js | wantAgent | 读、写 | wantAgent | 是 | 点击按钮时触发的WantAgent |
//publish回调 | extras | 读、写 | Array\<String\> | 否 | 按钮扩展信息 |
function publishCallback(err) { | icon | 读、写 | image.PixelMap | 否 | 按钮图标 |
console.info("==========================>publishCallback=======================>"); | userInput | 读、写 | NotificationUserInput | 否 | 用户输入对象实例 |
}
//通知Request对象 - NotificationUserInput类型说明
var notificationRequest = {
id: 1, | 名称 | 读写属性 | 类型 | 必填 | 描述 |
content: { | -------- | -------- | ------ | ---- | ----------------------------- |
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, | inputKey | 读、写 | string | 是 | 用户输入时用于标识此输入的key |
normal: {
title: "test_title",
text: "test_text", - 返回值
additionalText: "test_additionalText"
} void
}
} - 示例
Notification.publish(notificationRequest, publishCallback)
``` ```js
//publish回调
function publishCallback(err) {
console.info("==========================>publishCallback=======================>");
#### Notification.publish(request: NotificationRequest) }
//通知Request对象
- 接口说明 var notificationRequest = {
id: 1,
发布通知(Promise形式) content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
- 返回值 normal: {
title: "test_title",
返回值为Promise<**void**> text: "test_text",
additionalText: "test_additionalText"
- 示例 }
}
```js }
//通知Request对象 Notification.publish(notificationRequest, publishCallback)
var notificationRequest = { ```
notificationId: 1,
content: {
contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: { #### Notification.publish(request: NotificationRequest)
title: "test_title",
text: "test_text", - 接口说明
additionalText: "test_additionalText"
} 发布通知(Promise形式)
}
} - 返回值
Notification.publish(notificationRequest).then((void) => {
console.info("==========================>publishCallback=======================>"); Promise\<void\>
});
- 示例
```
```js
//通知Request对象
var notificationRequest = {
#### Notification.cancel(id: number, label: string, callback: AsyncCallback<void>) notificationId: 1,
content: {
- 接口说明 contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
取消与指定id和label相匹配的已发布通知(callback形式) title: "test_title",
text: "test_text",
- cancel参数描述 additionalText: "test_additionalText"
}
| 名称 | 读写属性 | 类型 | 必填 | 描述 | }
| -------- | -------- | ------------------- | ---- | -------------------- | }
| id | 只读 | number | 是 | 通知ID | Notification.publish(notificationRequest).then((void) => {
| lable | 只读 | string | 是 | 通知标签 | console.info("==========================>publishCallback=======================>");
| callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | });
- 返回值 ```
返回值为void
- 示例 #### Notification.cancel(id: number, label: string, callback: AsyncCallback\<void\>)
```js - 接口说明
//cancel回调
function cancelCallback(err) { 取消与指定id和label相匹配的已发布通知(callback形式)
console.info("==========================>cancelCallback=======================>");
} - cancel参数描述
Notification.cancel(0, "label", cancelCallback)
``` | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | -------------------- |
| id | 只读 | number | 是 | 通知ID |
| lable | 只读 | string | 是 | 通知标签 |
#### Notification.cancel(id:number, label?:string) | callback | 只读 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法 |
- 接口说明 - 返回值
取消与指定id相匹配的已发布通知,label可以指定也可以不指定(Promise形式) void
- cancel参数描述 - 示例
| 名称 | 读写属性 | 类型 | 必填 | 描述 | ```js
| ----- | -------- | ------ | ---- | -------- | //cancel回调
| id | 只读 | number | 是 | 通知ID | function cancelCallback(err) {
| lable | 只读 | string | 是 | 通知标签 | console.info("==========================>cancelCallback=======================>");
}
- 返回值 Notification.cancel(0, "label", cancelCallback)
```
返回值为Promise<**void**>
- 示例
#### Notification.cancel(id:number, label?:string)
```js
Notification.cancel(0).then((void) => { - 接口说明
console.info("==========================>cancelCallback=======================>");
}); 取消与指定id相匹配的已发布通知,label可以指定也可以不指定(Promise形式)
```
- cancel参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
#### Notification.cancel(id: number, callback: AsyncCallback<void>) | ----- | -------- | ------ | ---- | -------- |
| id | 只读 | number | 是 | 通知ID |
- 接口说明 | lable | 只读 | string | 是 | 通知标签 |
取消与指定id相匹配的已发布通知(callback形式) - 返回值
- cancel参数描述 Promise\<void\>
| 名称 | 读写属性 | 类型 | 必填 | 描述 | - 示例
| -------- | -------- | ------------------- | ---- | -------------------- |
| id | 只读 | number | 是 | 通知ID | ```js
| callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | Notification.cancel(0).then((void) => {
console.info("==========================>cancelCallback=======================>");
- 返回值 });
```
返回值为void
- 示例
#### Notification.cancel(id: number, callback: AsyncCallback\<void\>)
```js
//cancel回调 - 接口说明
function cancelCallback(err) {
console.info("==========================>cancelCallback=======================>"); 取消与指定id相匹配的已发布通知(callback形式)
}
Notification.cancel(0, cancelCallback) - cancel参数描述
```
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | -------------------- |
| id | 只读 | number | 是 | 通知ID |
#### Notification.cancelAll(callback: AsyncCallback<void>) | callback | 只读 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法 |
- 接口说明 - 返回值
取消所有已发布的通知(callback形式) void
- cancelAll参数描述 - 示例
| 名称 | 读写属性 | 类型 | 必填 | 描述 | ```js
| -------- | -------- | ------------------- | ---- | -------------------- | //cancel回调
| callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | function cancelCallback(err) {
console.info("==========================>cancelCallback=======================>");
- 返回值 }
Notification.cancel(0, cancelCallback)
返回值为void ```
- 示例
```js #### Notification.cancelAll(callback: AsyncCallback\<void\>)
//cancel回调
function cancelAllback(err) { - 接口说明
console.info("==========================>cancelAllback=======================>");
} 取消所有已发布的通知(callback形式)
Notification.cancelAll(cancelCallback)
``` - cancelAll参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | -------------------- |
#### Notification.cancelAll() | callback | 只读 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法 |
- 接口说明 - 返回值
取消所有已发布的通知(callback形式) void
- 参数描述 - 示例
无参数 ```js
//cancel回调
- 返回值 function cancelAllback(err) {
console.info("==========================>cancelAllback=======================>");
返回值为void }
Notification.cancelAll(cancelCallback)
- 示例 ```
```js
Notification.cancelAll().then((void) => {
console.info("==========================>cancelAllback=======================>"); #### Notification.cancelAll()
});
``` - 接口说明
#### Notification.addSlot(type: SlotType, callback: AsyncCallback<void>) 取消所有已发布的通知(callback形式)
- 接口说明 - 参数描述
创建通知通道(callback形式) 无参数
- addSlot参数描述 - 返回值
| 名称 | 读写属性 | 类型 | 必填 | 描述 | void
| -------- | -------- | ------------------- | ---- | ---------------------- |
| type | 只读 | SlotType | 是 | 要创建的通知通道的类型 | - 示例
| callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 |
```js
- SlotType类型说明 Notification.cancelAll().then((void) => {
console.info("==========================>cancelAllback=======================>");
| 名称 | 读写属性 | 类型 | 必填 | 描述 | });
| -------------------- | -------- | -------- | ---- | -------- | ```
| SOCIAL_COMMUNICATION | 只读 | SlotType | 否 | 社交类型 |
| SERVICE_INFORMATION | 只读 | SlotType | 否 | 服务类型 |
| CONTENT_INFORMATION | 只读 | SlotType | 否 | 内容类型 |
| OTHER_TYPES | 只读 | SlotType | 否 | 其他类型 | #### Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>)
* 返回值 - 接口说明
返回值为void 创建通知通道(callback形式)
* 示例 - addSlot参数描述
```js | 名称 | 读写属性 | 类型 | 必填 | 描述 |
//addslot回调 | -------- | -------- | --------------------- | ---- | ------------------------------------------ |
function addSlotCallBack(err) { | slot | 只读 | NotificationSlot | 是 | 要创建的通知通道,由{NotificationSlot}设置 |
console.info("==========================>addSlotCallBack=======================>"); | callback | 只读 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法 |
}
Notification.addSlot(SOCIAL_COMMUNICATION, addSlotCallBack) - NotificationSlot类型说明
```
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------------------- | -------- | --------------- | ---- | ------------------------------------------ |
| type | 读、写 | SlotType | 是 | 通道类型 |
#### Notification.addSlot(type: SlotType) | level | 读、写 | number | 否 | 通知级别,不设置则根据通知渠道类型有默认值 |
| desc | 读、写 | string | 否 | 通知渠道描述信息 |
- 接口说明 | badgeFlag | 读、写 | boolean | 否 | 是否显示角标 |
| bypassDnd | 读、写 | boolean | 否 | 置是否在系统中绕过免打扰模式 |
创建通知通道(Promise形式) | lockscreenVisibility | 读、写 | boolean | 否 | 在锁定屏幕上显示通知的模式 |
| vibrationEnabled | 读、写 | boolean | 否 | 是否可振动 |
- addSlot参数描述 | sound | 读、写 | string | 否 | 通知提示音 |
| lightEnabled | 读、写 | boolean | 否 | 是否闪灯 |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | lightColor | 读、写 | number | 否 | 通知灯颜色 |
| ---- | -------- | -------- | ---- | ---------------------- | | vibrationValues | 读、写 | Array\<number\> | 否 | 通知振动样式 |
| type | 只读 | SlotType | 是 | 要创建的通知通道的类型 |
* 返回值
- 返回值
void
返回值为Promise<**void**>
* 示例
- 示例
```js
```js //addslot回调
Notification.addSlot(SOCIAL_COMMUNICATION).then((void) => { function addSlotCallBack(err) {
console.info("==========================>addSlotCallback=======================>"); console.info("==========================>addSlotCallBack=======================>");
}); }
``` //通知slot对象
var notificationSlot = {
#### Notification.getSlot(slotType: SlotType, callback: AsyncCallback<NotificationSlot>) type:SOCIAL_COMMUNICATION
}
- 接口说明 Notification.addSlot(notificationSlot, addSlotCallBack)
```
获取一个通知通道(callback形式)
- getSlot参数描述
#### Notification.addSlot(slot: NotificationSlot)
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ------------------------------- | ---- | ----------------------------------------------------------- | - 接口说明
| slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 |
| callback | 只读 | AsyncCallback<NotificationSlot> | 是 | 表示被指定的回调方法 | 创建通知通道(Promise形式)
- 返回值 - addSlot参数描述
返回值为void | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---- | -------- | ---------------- | ---- | ------------------------------------------ |
- 示例 | slot | 只读 | NotificationSlot | 是 | 要创建的通知通道,由{NotificationSlot}设置 |
```js - 返回值
//getSlot回调
function getSlotCallback(err,data) { Promise\<void\>
console.info("==========================>getSlotCallback=======================>");
} - 示例
var slotType = SOCIAL_COMMUNICATION;
Notification.getSlot(slotType, getSlotCallback) ```js
``` //通知slot对象
var notificationSlot = {
notificationId: 0,
type:SOCIAL_COMMUNICATION
#### Notification.getSlot(slotType) }
Notification.addSlot(notificationSlot).then((void) => {
- 接口说明 console.info("==========================>addSlotCallback=======================>");
});
获取一个通知通道(Promise形式) ```
* getSlot参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 | #### Notification.addSlot(type: SlotType, callback: AsyncCallback\<void\>)
| -------- | -------- | -------- | ---- | ----------------------------------------------------------- |
| slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | - 接口说明
* 返回值 创建通知通道(callback形式)
返回值为Promise<NotificationSlot> - addSlot参数描述
* 示例 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | ---------------------- |
```js | type | 只读 | SlotType | 是 | 要创建的通知通道的类型 |
var slotType = SOCIAL_COMMUNICATION; | callback | 只读 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法 |
Notification.getSlot(slotType).then((data) => {
console.info("==========================>getSlotCallback=======================>"); - SlotType类型说明
```
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------------------- | -------- | -------- | ---- | -------- |
| SOCIAL_COMMUNICATION | 只读 | SlotType | 否 | 社交类型 |
#### Notification.getSlots(callback: AsyncCallback<Array<NotificationSlot>>) | SERVICE_INFORMATION | 只读 | SlotType | 否 | 服务类型 |
| CONTENT_INFORMATION | 只读 | SlotType | 否 | 内容类型 |
- 接口说明 | OTHER_TYPES | 只读 | SlotType | 否 | 其他类型 |
获取此应用程序的所有通知通道(callback形式) - 返回值
- getSlots参数描述 void
| 名称 | 读写属性 | 类型 | 必填 | 描述 | - 示例
| -------- | -------- | ------------------------------- | ---- | -------------------- |
| callback | 只读 | AsyncCallback<NotificationSlot> | 是 | 表示被指定的回调方法 | ```js
//addslot回调
- 返回值 function addSlotCallBack(err) {
console.info("==========================>addSlotCallBack=======================>");
返回值为void }
Notification.addSlot(SOCIAL_COMMUNICATION, addSlotCallBack)
- 示例 ```
```js
//getSlots回调
function getSlotsCallback(err,data) { #### Notification.addSlot(type: SlotType)
console.info("==========================>getSlotsCallback=======================>");
} - 接口说明
Notification.getSlots(getSlotsCallback)
``` 创建通知通道(Promise形式)
- addSlot参数描述
#### Notification.getSlots() | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---- | -------- | -------- | ---- | ---------------------- |
- 接口说明 | type | 只读 | SlotType | 是 | 要创建的通知通道的类型 |
获取此应用程序的所有通知通道(Promise形式) - 返回值
- getSlots参数描述 Promise\<void\>
无参数 - 示例
- 返回值 ```js
Notification.addSlot(SOCIAL_COMMUNICATION).then((void) => {
返回值为Promise<Array<NotificationSlot>> console.info("==========================>addSlotCallback=======================>");
});
- 示例 ```
```js
Notification.getSlots().then((data) => {
console.info("==========================>getSlotsCallback=======================>"); #### Notification.addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>)
```
- 接口说明
创建多个通知通道(callback形式)
#### Notification.removeSlot(slotType: SlotType, callback: AsyncCallback<void>)
- addSlots数描述
- 接口说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
根据通知通道类型删除创建的通知通道(callback形式) | -------- | -------- | ------------------------- | ---- | ------------------------------------------ |
| slots | 只读 | Array\<NotificationSlot\> | 是 | 要创建的通知通道,由{NotificationSlot}设置 |
- removeSlot参数描述 | callback | 只读 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法 |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | - 返回值
| -------- | -------- | ------------------- | ---- | ----------------------------------------------------------- |
| SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | void
| callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 |
- 示例
-
```js
返回值为void //addSlots回调
function addSlotsCallBack(err) {
- 示例 console.info("==========================>addSlotsCallBack=======================>");
}
```js //通知slot对象
//removeSlot回调 var notificationSlot = {
function removeSlotCallback(err) { notificationId: 0,
console.info("==========================>removeSlotCallback=======================>"); type:SOCIAL_COMMUNICATION
} }
var slotType = SOCIAL_COMMUNICATION; //通知slot array 对象
Notification.removeSlot(slotType,removeSlotCallback) var notificationSlotArray = new Array();
``` notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray, addSlotsCallBack)
```
#### Notification.removeSlot(slotType: SlotType)
- 接口说明
#### Notification.addSlots(slots: Array\<NotificationSlot\>)
根据通知通道类型删除创建的通知通道(Promise形式)
- 接口说明
- removeSlot参数描述
创建多个通知通道(Promise形式)
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | -------- | ---- | ----------------------------------------------------------- | - addSlots数描述
| SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 |
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
- | ----- | -------- | ------------------------- | ---- | ------------------------------------------ |
| slots | 只读 | Array\<NotificationSlot\> | 是 | 要创建的通知通道,由{NotificationSlot}设置 |
返回值为Promise<**void**>
- 返回值
- 示例
Promise\<void\>
```js
var slotType = SOCIAL_COMMUNICATION; - 示例
Notification.removeSlot(slotType).then((void) => {
console.info("==========================>removeSlotCallback=======================>"); ```js
``` //通知slot对象
var notificationSlot = {
notificationId: 0,
type:SOCIAL_COMMUNICATION
#### Notification.removeAllSlots(callback: AsyncCallback<void>) }
//通知slot array 对象
- 接口说明 var notificationSlotArray = new Array();
notificationSlotArray[0] = notificationSlot;
删除所有通知通道(callback形式)
Notification.addSlots(notificationSlotArray).then((void) => {
- removeAllSlots参数描述 console.info("==========================>addSlotCallback=======================>");
});
| 名称 | 读写属性 | 类型 | 必填 | 描述 | ```
| -------- | -------- | ------------------- | ---- | -------------------- |
| callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 |
- #### Notification.getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>)
返回值为void - 接口说明
- 示例 获取一个通知通道(callback形式)
```js - getSlot参数描述
function removeAllCallBack(err) {
console.info("================>removeAllCallBack=======================>"); | 名称 | 读写属性 | 类型 | 必填 | 描述 |
} | -------- | -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
Notification.removeAllSlots(removeAllCallBack) | slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 |
``` | callback | 只读 | AsyncCallback\<NotificationSlot\> | 是 | 表示被指定的回调方法 |
- 返回值
#### Notification.removeAllSlots() void
- 接口说明 - 示例
删除所有通知通道(Promise形式) ```js
//getSlot回调
- removeAllSlots参数描述 function getSlotCallback(err,data) {
console.info("==========================>getSlotCallback=======================>");
参数无 }
var slotType = SOCIAL_COMMUNICATION;
- Notification.getSlot(slotType, getSlotCallback)
```
返回值为Promise<**void**>
- 示例
#### Notification.getSlot(slotType)
```js
- 接口说明
Notification.removeAllSlots().then((void) => {
console.info("==========================>removeAllCallBack=======================>"); 获取一个通知通道(Promise形式)
});
``` - getSlot参数描述
#### Notification.getAllActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>) | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | -------- | ---- | ----------------------------------------------------------- |
- 接口说明 | slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 |
获取活动通知(Callback形式) - 返回值
- getAllActiveNotifications参数描述 Promise\<NotificationSlot\>
| 名称 | 读写属性 | 类型 | 必填 | 描述 | - 示例
| -------- | -------- | ----------------------------------------- | ---- | -------------------- |
| callback | 只读 | AsyncCallback<Array<NotificationRequest>> | 是 | 获取活动通知回调函数 | ```js
var slotType = SOCIAL_COMMUNICATION;
- Notification.getSlot(slotType).then((data) => {
console.info("==========================>getSlotCallback=======================>");
返回值为void ```
- 示例
```js #### Notification.getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>)
function getAllActiveNotificationsCallback(err, data) {
console.info("==========================>getAllActiveNotificationsCallback=======================>"); - 接口说明
}
获取此应用程序的所有通知通道(callback形式)
Notification.getAllActiveNotifications(getAllActiveNotificationsCallback);
``` - getSlots参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------------------- | ---- | -------------------- |
#### Notification.getAllActiveNotifications() | callback | 只读 | AsyncCallback\<NotificationSlot\> | 是 | 表示被指定的回调方法 |
- 接口说明 - 返回值
获取活动通知(Promise形式) void
- getAllActiveNotifications参数描述 - 示例
```js
//getSlots回调
- function getSlotsCallback(err,data) {
console.info("==========================>getSlotsCallback=======================>");
返回值为Promise<Array<NotificationRequest>> }
Notification.getSlots(getSlotsCallback)
- 示例 ```
```js
Notification.getAllActiveNotifications().then((data) => {
console.info("==========================>getAllActiveNotificationsCallback=======================>"); #### Notification.getSlots()
});
``` - 接口说明
获取此应用程序的所有通知通道(Promise形式)
#### Notification.getActiveNotificationCount(callback: AsyncCallback<**number**>) - getSlots参数描述
- 接口说明 无参数
获取当前应用的活动通知数(Callback形式) - 返回值
- getActiveNotificationCount参数描述 Promise\<Array\<NotificationSlot\>\>
| 名称 | 读写属性 | 类型 | 必填 | 描述 | - 示例
| -------- | -------- | ------------------------- | ---- | ---------------------- |
| callback | 只读 | AsyncCallback<**number**> | 是 | 获取活动通知数回调函数 | ```js
Notification.getSlots().then((data) => {
- console.info("==========================>getSlotsCallback=======================>");
```
返回值为void
- 示例
#### Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>)
```js
function getActiveNotificationCountCallback(err, data) { - 接口说明
console.info("==========================>getActiveNotificationCountCallback=======================>");
} 根据通知通道类型删除创建的通知通道(callback形式)
Notification.getActiveNotificationCount(getActiveNotificationCountCallback); - removeSlot参数描述
```
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | ----------------------------------------------------------- |
| SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 |
#### Notification.getActiveNotificationCount() | callback | 只读 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法 |
- 接口说明 - 返回值
获取当前应用的活动通知数(Promise形式) void
- getActiveNotificationCount参数描述 - 示例
```js
//removeSlot回调
- function removeSlotCallback(err) {
console.info("==========================>removeSlotCallback=======================>");
返回值为Promise<**number**> }
var slotType = SOCIAL_COMMUNICATION;
- 示例 Notification.removeSlot(slotType,removeSlotCallback)
```
```js
Notification.getActiveNotificationCount().then((data) => {
console.info("==========================>getActiveNotificationCountCallback=======================>");
}); #### Notification.removeSlot(slotType: SlotType)
```
- 接口说明
根据通知通道类型删除创建的通知通道(Promise形式)
#### Notification.getActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>)
- removeSlot参数描述
- 接口说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
获取当前应用的活动通知(Callback形式) | -------- | -------- | -------- | ---- | ----------------------------------------------------------- |
| SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 |
- getActiveNotifications参数描述
- 返回值
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ----------------------------------------- | ---- | ------------------------------ | Promise\<void\>
| callback | 只读 | AsyncCallback<Array<NotificationRequest>> | 是 | 获取当前应用的活动通知回调函数 |
- 示例
-
```js
返回值为void var slotType = SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType).then((void) => {
- 示例 console.info("==========================>removeSlotCallback=======================>");
```
```js
function getActiveNotificationsCallback(err, data) {
console.info("==========================>getActiveNotificationsCallback=======================>");
} #### Notification.removeAllSlots(callback: AsyncCallback\<void\>)
Notification.getActiveNotifications(getActiveNotificationsCallback); - 接口说明
```
删除所有通知通道(callback形式)
- removeAllSlots参数描述
#### Notification.getActiveNotifications()
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
- 接口说明 | -------- | -------- | --------------------- | ---- | -------------------- |
| callback | 只读 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法 |
获取当前应用的活动通知(Promise形式)
- 返回值
- getActiveNotifications参数描述
void
- 示例
-
```js
返回值为Promise<Array<NotificationRequest>> function removeAllCallBack(err) {
console.info("================>removeAllCallBack=======================>");
- 示例 }
Notification.removeAllSlots(removeAllCallBack)
```js ```
Notification.getActiveNotifications().then((data) => {
console.info("==========================>getActiveNotificationsCallback=======================>");
});
``` #### Notification.removeAllSlots()
- 接口说明
#### WantAgent接口 删除所有通知通道(Promise形式)
#### 导入模块 - removeAllSlots参数描述
```js 参数无
import WantAgent from '@ohos.wantAgent';
``` - 返回值
#### WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>) Promise\<void\>
- 接口说明 - 示例
创建WantAgent(callback形式) ```js
Notification.removeAllSlots().then((void) => {
- getWantAgent参数描述 console.info("==========================>removeAllCallBack=======================>");
});
```
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ------------------------ | ---- | ----------------------- |
| info | 只读 | WantAgentInfo | 是 | WantAgent信息 |
| callback | 只读 | AsyncCallback<WantAgent> | 是 | 创建WantAgent的回调方法 | #### Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>)
- WantAgentInfo类型说明 - 接口说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 | 订阅通知并指定订阅信息(callback形式)
| -------------- | -------- | ------------------------------- | ---- | ---------------------- |
| wants | 读、写 | Array<Want> | 是 | 将被执行的动作列表 | - subscribe参数描述
| operationType | 读、写 | wantAgent.OperationType | 是 | 动作类型 |
| requestCode | 读、写 | number | 是 | 使用者定义的一个私有值 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| wantAgentFlags | 读、写 | Array<wantAgent.WantAgentFlags> | 否 | 动作执行属性 | | ---------- | -------- | ------------------------- | ---- | ---------------- |
| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 | | subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 |
| info | 只读 | NotificationSubscribeInfo | 是 | 订阅信息 |
- | callback | 只读 | AsyncCallback\<void\> | 是 | 订阅动作回调函数 |
WantAgentFlags类型说明
- NotificationSubscriber类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------------------- | -------- | ---- | ---- | ------------------------------------------------------------ | | ------------------------------------------------------------ | -------- | -------- | ---- | -------------------------- |
| ONE_TIME_FLAG | 只读 | enum | 否 | WantAgent仅能使用一次 | | onConsume?:(data: SubscribeCallbackData) | 读、写 | function | 否 | 接收通知回调函数 |
| NO_BUILD_FLAG | 只读 | enum | 否 | 如果描述WantAgent对象不存在,则不创建它,直接返回null | | onCancel?:(data: SubscribeCallbackData) | 读、写 | function | 否 | 删除通知回调函数 |
| CANCEL_PRESENT_FLAG | 只读 | enum | 否 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象 | | onUpdate?:(data: NotificationSortingMap) | 读、写 | function | 否 | 更新通知排序回调函数 |
| UPDATE_PRESENT_FLAG | 只读 | enum | 否 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据 | | onConnect?:() | 读、写 | function | 否 | 注册订阅回调函数 |
| CONSTANT_FLAG | 只读 | enum | 否 | WantAgent是不可变的 | | onDisconnect?:() | 读、写 | function | 否 | 取消订阅回调函数 |
| REPLACE_ELEMENT | 只读 | enum | 否 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代 | | onDestroy?:() | 读、写 | function | 否 | 服务失联回调函数 |
| REPLACE_ACTION | 只读 | enum | 否 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代 | | onDisturbModeChange?:(mode: notification.DoNotDisturbMode) | 读、写 | function | 否 | 免打扰模式变更回调函数 |
| REPLACE_URI | 只读 | enum | 否 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代 | | onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) | 读、写 | function | 否 | 免打扰时间选项变更回调函数 |
| REPLACE_ENTITIES | 只读 | enum | 否 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代 |
| REPLACE_BUNDLE | 只读 | enum | 否 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代 | - SubscribeCallbackData 类型说明
- OperationType类型说明 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| --------------- | -------- | ---------------------- | ---- | -------- |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | request | 只读 | NotificationRequest | 是 | 通知内容 |
| ----------------- | -------- | ---- | ---- | ----------------------- | | sortingMap | 只读 | NotificationSortingMap | 否 | 排序信息 |
| UNKNOWN_TYPE | 只读 | enum | 否 | 不识别的类型 | | reason | 只读 | number | 否 | 删除原因 |
| START_ABILITY | 只读 | enum | 否 | 开启一个有页面的Ability | | sound | 只读 | string | 否 | 通知声音 |
| START_ABILITIES | 只读 | enum | 否 | 开启多个有页面的Ability | | vibrationValues | 只读 | Array\<number\> | 否 | 通知震动 |
| START_SERVICE | 只读 | enum | 否 | 开启一个无页面的ability |
| SEND_COMMON_EVENT | 只读 | enum | 否 | 发送一个公共事件 | - NotificationSortingMap类型说明
- | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------------- | -------- | ------------------------------------ | ---- | ---------------- |
返回值为void | sortings | 只读 | {[key: string]: NotificationSorting} | 是 | 通知排序信息数组 |
| sortedHashCode | 只读 | Array\<string\> | 是 | 通知唯一标识数组 |
- 示例
- NotificationSorting 类型说明
```js
import wantAgent from '@ohos.wantAgent'; | 名称 | 读写属性 | 类型 | 必填 | 描述 |
import { OperationType, Flags } from '@ohos.wantagent'; | -------- | -------- | ---------------- | ---- | ------------ |
| slot | 只读 | NotificationSlot | 是 | 通知通道内容 |
//getWantAgent回调 | hashCode | 只读 | string | 是 | 通知唯一标识 |
function getWantAgentCallback(err, data) { | ranking | 只读 | number | 是 | 通知排序序号 |
console.info("==========================>getWantAgentCallback=======================>");
} - DoNotDisturbMode类型说明
//WantAgentInfo对象
var wantAgentInfo = { | 名称 | 读写属性 | 类型 | 必填 | 描述 |
wants: [ | -------------- | -------- | ---------------- | ---- | ---------------------------- |
{ | ALLOW_ALL | 只读 | DoNotDisturbMode | 否 | 全部绕过免打扰 |
deviceId: "deviceId", | ALLOW_PRIORITY | 只读 | DoNotDisturbMode | 否 | 指定优先级通知可以绕过免打扰 |
bundleName: "com.neu.setResultOnAbilityResultTest1", | ALLOW_NONE | 只读 | DoNotDisturbMode | 否 | 全部免打扰 |
abilityName: "com.example.test.MainAbility", | ALLOW_ALARMS | 只读 | DoNotDisturbMode | 否 | 闹钟类型通知可以绕过免打扰 |
action: "action1",
entities: ["entity1"], - DoNotDisturbType类型说明
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters: | 名称 | 读写属性 | 类型 | 描述 |
{ | ------------ | -------- | --------------------- | ---------------------------------------- |
mykey0: 2222, | TYPE_NONE | 只读 | enum DoNotDisturbType | 非通知勿扰类型 |
mykey1: [1, 2, 3], | TYPE_ONCE | 只读 | enum DoNotDisturbType | 以设置时间段(只看小时和分钟)一次执行勿扰 |
mykey2: "[1, 2, 3]", | TYPE_DAILY | 只读 | enum DoNotDisturbType | 以设置时间段(只看小时和分钟)每天执行勿扰 |
mykey3: "ssssssssssssssssssssssssss", | TYPE_CLEARLY | 只读 | enum DoNotDisturbType | 以设置时间段(明确年月日时分)执行勿扰 |
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - DoNotDisturbDate类型说明
mykey6: true,
} | 名称 | 读写属性 | 类型 | 描述 |
} | ----- | -------- | ---------------- | ------------------------ |
], | type | 读写 | DoNotDisturbType | 指定免打扰设置的时间类型 |
operationType: OperationType.START_ABILITIES, | begin | 读写 | Date | 指定免打扰设置的起点时间 |
requestCode: 0, | end | 读写 | Date | 指定免打扰设置的终点时间 |
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG]
} - NotificationSubscribeInfo类型说明
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) | 名称 | 读写属性 | 类型 | 必填 | 描述 |
``` | ----------- | -------- | --------------- | ---- | ------------------------------- |
| bundleNames | 读、写 | Array\<string\> | 否 | 指定订阅哪些包名的APP发来的通知 |
| userId | 读、写 | number | 否 | 指定订阅哪个用户下发来的通知 |
#### WantAgent.getWantAgent(info: WantAgentInfo): Promise<WantAgent> - 返回值
- 接口说明 void
创建WantAgent(Promise形式) - 示例
- getWantAgent参数描述 ```js
//subscribe回调
function subscribeCallback(err) {
| 名称 | 读写属性 | 类型 | 必填 | 描述 | console.info("==========================>subscribeCallback=======================>");
| ---- | -------- | ------------- | ---- | ------------- | }
| info | 只读 | WantAgentInfo | 是 | WantAgent信息 | function onConsumeCallback(err, data) {
console.info("==========================>onConsumeCallback=======================>");
- }
var subscriber = {
返回值为Promise<WantAgent> onConsume:onConsumeCallback;
}
- 示例 var info = {
bundleNames:["bundleName1","bundleName2"]
```js }
import wantAgent from '@ohos.wantAgent'; Notification.subscribe(subscriber, info, subscribeCallback);
import { OperationType, Flags } from '@ohos.wantagent'; ```
//WantAgentInfo对象
var wantAgentInfo = {
wants: [ #### Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>)
{
deviceId: "deviceId", - 接口说明
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility", 订阅通知并指定订阅信息(callback形式)
action: "action1",
entities: ["entity1"], - subscribe参数描述
type: "MIMETYPE",
uri: "key={true,true,false}", | 名称 | 读写属性 | 类型 | 必填 | 描述 |
parameters: | ---------- | -------- | ---------------------- | ---- | ---------------- |
{ | subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 |
mykey0: 2222, | callback | 只读 | AsyncCallback\<void\> | 是 | 订阅动作回调函数 |
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]", - 返回值
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false], void
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true, - 示例
}
} ```js
], function subscribeCallback(err) {
operationType: OperationType.START_ABILITIES, console.info("==========================>subscribeCallback=======================>");
requestCode: 0, }
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] function onConsumeCallback(err, data) {
} console.info("==========================>onConsumeCallback=======================>");
}
wantAgent.getWantAgent(wantAgentInfo).then((data) => { var subscriber = {
console.info("==========================>getWantAgentCallback=======================>"); onConsume:onConsumeCallback;
}); }
``` Notification.subscribe(subscriber, subscribeCallback);
```
#### WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback<string>)
#### Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo)
- 接口说明
- 接口说明
获取WantAgent实例的包名(callback形式)
订阅通知并指定订阅信息(Promise形式)
- getBundleName参数描述
- subscribe参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | --------------------------------- | | ---------- | -------- | ------------------------- | ---- | ------------ |
| agent | 只读 | WantAgent | 是 | WantAgent对象 | | subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 |
| callback | 只读 | AsyncCallback<string> | 是 | 获取WantAgent实例的包名的回调方法 | | info | 只读 | NotificationSubscribeInfo | 否 | 订阅信息 |
- 返回值为void - 返回值
- 示例 Promise\<void\>
```js - 示例
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent'; ```js
function onConsumeCallback(err, data) {
//wantAgent对象 console.info("==========================>onConsumeCallback=======================>");
var WantAgent; }
var subscriber = {
//getWantAgent回调 onConsume:onConsumeCallback;
function getWantAgentCallback(err, data) { };
console.info("==========================>getWantAgentCallback=======================>"); Notification.subscribe(subscriber).then((void) => {
if (err.code == 0) { console.info("==========================>subscribeCallback=======================>");
WantAgent = data; });
} else { ```
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象 #### Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>)
var wantAgentInfo = {
wants: [ - 接口说明
{
deviceId: "deviceId", 取消订阅(callbcak形式)
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility", - unsubscribe参数描述
action: "action1",
entities: ["entity1"], | 名称 | 读写属性 | 类型 | 必填 | 描述 |
type: "MIMETYPE", | ---------- | -------- | ---------------------- | ---- | -------------------- |
uri: "key={true,true,false}", | subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 |
parameters: | callback | 只读 | AsyncCallback\<void\> | 是 | 取消订阅动作回调函数 |
{
mykey0: 2222, - 返回值
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]", void
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false], - 示例
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true, ```js
} function unsubscribeCallback(err) {
} console.info("==========================>unsubscribeCallback=======================>");
], }
operationType: OperationType.START_ABILITIES, function onConsumeCallback(err, data) {
requestCode: 0, console.info("==========================>onConsumeCallback=======================>");
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] }
} var subscriber = {
onConsume:onConsumeCallback;
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) }
Notification.unsubscribe(subscriber, unsubscribeCallback);
//getBundleName回调 ```
function getBundleNameCallback(err, data) {
console.info("==========================>getBundleNameCallback=======================>");
}
wantAgent.getBundleName(WantAgent, getBundleNameCallback) #### Notification.unsubscribe(subscriber: NotificationSubscriber)
```
- 接口说明
取消订阅(Promise形式)
#### WantAgent.getBundleName(agent: WantAgent): Promise<string>
- unsubscribe参数描述
- 接口说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
获取WantAgent实例的包名(Promise形式) | ---------- | -------- | ---------------------- | ---- | ------------ |
| subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 |
- getBundleName参数描述
- 返回值
| 名称 | 读写属性 | 类型 | 必填 | 描述 | Promise\<void\>
| ----- | -------- | --------- | ---- | ------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 | - 示例
- ```js
function onConsumeCallback(err, data) {
返回值为Promise<string> console.info("==========================>onConsumeCallback=======================>");
}
- 示例 var subscriber = {
onConsume:onConsumeCallback;
```js };
import wantAgent from '@ohos.wantAgent'; Notification.unsubscribe(subscriber).then((void) => {
import { OperationType, Flags } from '@ohos.wantagent'; console.info("==========================>unsubscribeCallback=======================>");
});
//wantAgent对象 ```
var WantAgent;
//WantAgentInfo对象
var wantAgentInfo = { #### Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>)
wants: [
{ - 接口说明
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1", 设定指定包的通知使能状态(Callback形式)
abilityName: "com.example.test.MainAbility",
action: "action1", - enableNotification参数描述
entities: ["entity1"],
type: "MIMETYPE", | 名称 | 读写属性 | 类型 | 必填 | 描述 |
uri: "key={true,true,false}", | -------- | -------- | --------------------- | ---- | -------------------- |
parameters: | bundle | 只读 | BundleOption | 是 | 指定包信息 |
{ | enable | 只读 | boolean | 是 | 使能状态 |
mykey0: 2222, | callback | 只读 | AsyncCallback\<void\> | 是 | 设定通知使能回调函数 |
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]", - BundleOption类型说明
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false], | 名称 | 读写属性 | 类型 | 必填 | 描述 |
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], | ------ | -------- | ------ | ---- | ------ |
mykey6: true, | bundle | 读/写 | string | 是 | 包名 |
} | uid | 读/写 | number | 否 | 用户id |
} - 返回值
],
operationType: OperationType.START_ABILITIES, void
requestCode: 0,
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - 示例
}
```js
wantAgent.getWantAgent(wantAgentInfo).then((data) => { function enableNotificationCallback(err) {
console.info("==========================>getWantAgentCallback=======================>"); console.info("==========================>enableNotificationCallback=======================>");
WantAgent = data; }
}); var bundle = {
bundle:"bundleName1";
wantAgent.getBundleName(WantAgent).then((data) => { }
console.info("==========================>getBundleNameCallback=======================>"); Notification.enableNotification(bundle, false, enableNotificationCallback);
}); ```
```
#### Notification.enableNotification(bundle: BundleOption, enable: boolean)
#### WantAgent.getUid(agent: WantAgent, callback: AsyncCallback<number>)
- 接口说明
- 接口说明
设定指定包的通知使能状态(Promise形式)
获取WantAgent实例的用户ID(callback形式)
- enableNotification参数描述
- getUid参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------ | -------- | ------------ | ---- | ---------- |
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | bundle | 只读 | BundleOption | 是 | 指定包信息 |
| -------- | -------- | --------------------- | ---- | ----------------------------------- | | enable | 只读 | boolean | 是 | 使能状态 |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| callback | 只读 | AsyncCallback<number> | 是 | 获取WantAgent实例的用户ID的回调方法 | - 返回值
- 返回值为void Promise\<void\>
- 示例 - 示例
```js ```js
import wantAgent from '@ohos.wantAgent'; var bundle = {
import { OperationType, Flags } from '@ohos.wantagent'; bundle:"bundleName1";
}
//wantAgent对象 Notification.enableNotification(bundle, false).then((void) => {
var WantAgent; console.info("==========================>enableNotificationCallback=======================>");
});
//getWantAgent回调 ```
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
WantAgent = data; #### Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>)
} else {
console.info('----getWantAgent failed!----'); - 接口说明
}
} 获取指定包的通知使能状态(Callback形式)
//WantAgentInfo对象
var wantAgentInfo = { - isNotificationEnabled参数描述
wants: [
{ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
deviceId: "deviceId", | -------- | -------- | --------------------- | ---- | ------------------------ |
bundleName: "com.neu.setResultOnAbilityResultTest1", | bundle | 只读 | BundleOption | 是 | 指定包信息 |
abilityName: "com.example.test.MainAbility", | callback | 只读 | AsyncCallback\<void\> | 是 | 获取通知使能状态回调函数 |
action: "action1",
entities: ["entity1"], - 返回值
type: "MIMETYPE",
uri: "key={true,true,false}", void
parameters:
{ - 示例
mykey0: 2222,
mykey1: [1, 2, 3], ```js
mykey2: "[1, 2, 3]", function isNotificationEnabledCallback(err, data) {
mykey3: "ssssssssssssssssssssssssss", console.info("==========================>isNotificationEnabledCallback=======================>");
mykey4: [false, true, false], }
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], var bundle = {
mykey6: true, bundle:"bundleName1";
} }
} Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback);
], ```
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG]
} #### Notification.isNotificationEnabled(bundle: BundleOption)
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - 接口说明
//getUid回调 获取指定包的通知使能状态(Promise形式)
function getUidCallback(err, data) {
console.info("==========================>getUidCallback=======================>"); - isNotificationEnabled参数描述
}
wantAgent.getUid(WantAgent, getUidCallback) | 名称 | 读写属性 | 类型 | 必填 | 描述 |
``` | ------ | -------- | ------------ | ---- | ---------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
- 返回值
#### WantAgent.getUid(agent: WantAgent): Promise<number>
Promise\<boolean\>
- 接口说明
- 示例
获取WantAgent实例的用户ID(Promise形式)
```js
- getUid参数描述 var bundle = {
bundle:"bundleName1";
}
| 名称 | 读写属性 | 类型 | 必填 | 描述 | Notification.isNotificationEnabled(bundle).then((data) => {
| ----- | -------- | --------- | ---- | ------------- | console.info("==========================>isNotificationEnabledCallback=======================>");
| agent | 只读 | WantAgent | 是 | WantAgent对象 | });
```
-
返回值为Promise<number>
#### Notification.isNotificationEnabled(callback: AsyncCallback\<boolean\>)
- 示例
- 接口说明
```js
import wantAgent from '@ohos.wantAgent'; 获取通知使能状态(Callback形式)
import { OperationType, Flags } from '@ohos.wantagent';
- isNotificationEnabled参数描述
//wantAgent对象
var WantAgent; | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | ------------------------ |
//WantAgentInfo对象 | callback | 只读 | AsyncCallback\<void\> | 是 | 获取通知使能状态回调函数 |
var wantAgentInfo = {
wants: [ - 返回值
{
deviceId: "deviceId", void
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility", - 示例
action: "action1",
entities: ["entity1"], ```js
type: "MIMETYPE", function isNotificationEnabledCallback(err, data) {
uri: "key={true,true,false}", console.info("==========================>isNotificationEnabledCallback=======================>");
parameters: }
{
mykey0: 2222, Notification.isNotificationEnabled(isNotificationEnabledCallback);
mykey1: [1, 2, 3], ```
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], #### Notification.isNotificationEnabled()
mykey6: true,
} - 接口说明
}
], 获取通知使能状态(Promise形式)
operationType: OperationType.START_ABILITIES,
requestCode: 0, - isNotificationEnabled参数描述
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG]
} | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------ | -------- | ------------ | ---- | ---------- |
wantAgent.getWantAgent(wantAgentInfo).then((data) => { | bundle | 只读 | BundleOption | 是 | 指定包信息 |
console.info("==========================>getWantAgentCallback=======================>");
WantAgent = data; - 返回值
});
Promise\<boolean\>
wantAgent.getUid(WantAgent).then((data) => {
console.info("==========================>getUidCallback=======================>"); - 示例
});
``` ```js
Notification.isNotificationEnabled().then((data) => {
console.info("==========================>isNotificationEnabledCallback=======================>");
});
#### WantAgent.cancel(agent: WantAgent, callback: AsyncCallback<void>) ```
- 接口说明
取消WantAgent实例(callback形式) #### Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>)
- cancel参数描述 - 接口说明
设定指定包的角标使能状态(Callback形式)
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ------------------- | ---- | --------------------------- | - displayBadge参数描述
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| callback | 只读 | AsyncCallback<void> | 是 | 取消WantAgent实例的回调方法 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | -------------------- |
- 返回值为void | bundle | 只读 | BundleOption | 是 | 指定包信息 |
| enable | 只读 | boolean | 是 | 使能状态 |
- 示例 | callback | 只读 | AsyncCallback\<void\> | 是 | 设定角标使能回调函数 |
```js - 返回值
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent'; void
//wantAgent对象 - 示例
var WantAgent;
```js
//getWantAgent回调 function displayBadgeCallback(err) {
function getWantAgentCallback(err, data) { console.info("==========================>displayBadgeCallback=======================>");
console.info("==========================>getWantAgentCallback=======================>"); }
if (err.code == 0) { var bundle = {
WantAgent = data; bundle:"bundleName1";
} else { }
console.info('----getWantAgent failed!----'); Notification.displayBadge(bundle, false, displayBadgeCallback);
} ```
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [ #### Notification.displayBadge(bundle: BundleOption, enable: boolean)
{
deviceId: "deviceId", - 接口说明
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility", 设定指定包的角标使能状态(Promise形式)
action: "action1",
entities: ["entity1"], - displayBadge参数描述
type: "MIMETYPE",
uri: "key={true,true,false}", | 名称 | 读写属性 | 类型 | 必填 | 描述 |
parameters: | ------ | -------- | ------------ | ---- | ---------- |
{ | bundle | 只读 | BundleOption | 是 | 指定包信息 |
mykey0: 2222, | enable | 只读 | boolean | 是 | 使能状态 |
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]", - 返回值
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false], Promise\<void\>
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true, - 示例
}
} ```js
], var bundle = {
operationType: OperationType.START_ABILITIES, bundle:"bundleName1";
requestCode: 0, }
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] Notification.displayBadge(bundle, false).then((void) => {
} console.info("==========================>displayBadgeCallback=======================>");
});
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) ```
//cancel回调
function cancelCallback(err, data) {
console.info("==========================>cancelCallback=======================>"); #### Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>)
}
wantAgent.cancel(WantAgent, cancelCallback) - 接口说明
```
获取指定包的角标使能状态(Callback形式)
- isBadgeDisplayed参数描述
#### WantAgent.cancel(agent: WantAgent): Promise<void>
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
- 接口说明 | -------- | -------- | --------------------- | ---- | ------------------------ |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
取消WantAgent实例(Promise形式) | callback | 只读 | AsyncCallback\<void\> | 是 | 获取角标使能状态回调函数 |
- cancel参数描述 - 返回值
void
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----- | -------- | --------- | ---- | ------------- | - 示例
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
```js
- function isBadgeDisplayedCallback(err, data) {
console.info("==========================>isBadgeDisplayedCallback=======================>");
返回值为Promise<void> }
var bundle = {
- 示例 bundle:"bundleName1";
}
```js Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);
import wantAgent from '@ohos.wantAgent'; ```
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent; #### Notification.isBadgeDisplayed(bundle: BundleOption)
//WantAgentInfo对象 - 接口说明
var wantAgentInfo = {
wants: [ 获取指定包的角标使能状态(Promise形式)
{
deviceId: "deviceId", - isBadgeDisplayed参数描述
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility", | 名称 | 读写属性 | 类型 | 必填 | 描述 |
action: "action1", | ------ | -------- | ------------ | ---- | ---------- |
entities: ["entity1"], | bundle | 只读 | BundleOption | 是 | 指定包信息 |
type: "MIMETYPE",
uri: "key={true,true,false}", - 返回值
parameters:
{ Promise\<boolean\>
mykey0: 2222,
mykey1: [1, 2, 3], - 示例
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss", ```js
mykey4: [false, true, false], var bundle = {
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], bundle:"bundleName1";
mykey6: true, }
} Notification.isBadgeDisplayed(bundle).then((data) => {
} console.info("==========================>isBadgeDisplayedCallback=======================>");
], });
operationType: OperationType.START_ABILITIES, ```
requestCode: 0,
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG]
}
#### Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>)
wantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>"); - 接口说明
WantAgent = data;
}); 设定指定包的通知通道状态(Callback形式)
wantAgent.cancel(WantAgent).then((data) => { - setSlotByBundle参数描述
console.info("==========================>cancelCallback=======================>");
}); | 名称 | 读写属性 | 类型 | 必填 | 描述 |
``` | -------- | -------- | --------------------- | ---- | -------------------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
| slot | 只读 | NotificationSlot | 是 | 通知通道 |
| callback | 只读 | AsyncCallback\<void\> | 是 | 设定通知通道回调函数 |
#### WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>)
- 返回值
- 接口说明
void
主动激发WantAgent实例(callback形式)
- 示例
- trigger参数描述
```js
function setSlotByBundleCallback(err) {
| 名称 | 读写属性 | 类型 | 必填 | 描述 | console.info("==========================>setSlotByBundleCallback=======================>");
| ----------- | -------- | --------------------------- | ---- | ------------------------------- | }
| agent | 只读 | WantAgent | 是 | WantAgent对象 | var bundle = {
| triggerInfo | 只读 | TriggerInfo | 是 | TriggerInfo对象 | bundle:"bundleName1";
| callback | 只读 | AsyncCallback<CompleteData> | 是 | 主动激发WantAgent实例的回调方法 | }
var notificationSlot = {
- TriggerInfo类型说明 type:SOCIAL_COMMUNICATION
}
| 名称 | 读写属性 | 类型 | 必填 | 描述 | Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);
| ---------- | -------- | -------------------- | ---- | ----------- | ```
| code | 读、写 | number | 是 | result code |
| want | 读、写 | Want | 否 | Want |
| permission | 读、写 | string | 否 | 权限定义 |
| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 | #### Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot)
- 返回值为void - 接口说明
- 示例
设定指定包的角标使能状态(Promise形式)
```js
import wantAgent from '@ohos.wantAgent'; - setSlotByBundle参数描述
import { OperationType, Flags } from '@ohos.wantagent';
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
//wantAgent对象 | ------ | -------- | ------------ | ---- | ---------- |
var WantAgent; | bundle | 只读 | BundleOption | 是 | 指定包信息 |
| enable | 只读 | boolean | 是 | 使能状态 |
//getWantAgent回调
function getWantAgentCallback(err, data) { - 返回值
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) { Promise\<void\>
WantAgent = data;
} else { - 示例
console.info('----getWantAgent failed!----');
} ```js
} var bundle = {
//WantAgentInfo对象 bundle:"bundleName1";
var wantAgentInfo = { }
wants: [ var notificationSlot = {
{ type:SOCIAL_COMMUNICATION
deviceId: "deviceId", }
bundleName: "com.neu.setResultOnAbilityResultTest1", Notification.displayBadge(bundle, notificationSlot).then((void) => {
abilityName: "com.example.test.MainAbility", console.info("==========================>setSlotByBundleCallback=======================>");
action: "action1", });
entities: ["entity1"], ```
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{ #### Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>)
mykey0: 2222,
mykey1: [1, 2, 3], - 接口说明
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss", 获取指定包的通知通道(Callback形式)
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - getSlotsByBundle参数描述
mykey6: true,
} | 名称 | 读写属性 | 类型 | 必填 | 描述 |
} | -------- | -------- | ---------------------------------------- | ---- | -------------------- |
], | bundle | 只读 | BundleOption | 是 | 指定包信息 |
operationType: OperationType.START_ABILITIES, | callback | 只读 | AsyncCallback<Array\<NotificationSlot\>> | 是 | 获取通知通道回调函数 |
requestCode: 0,
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - 返回值
}
void
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
- 示例
//cancel回调
function triggerCallback(err, data) { ```js
console.info("==========================>triggerCallback=======================>"); function getSlotsByBundleCallback(err, data) {
} console.info("==========================>getSlotsByBundleCallback=======================>");
wantAgent.trigger(WantAgent, triggerCallback) }
``` var bundle = {
bundle:"bundleName1";
}
Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback);
#### WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>) ```
- 接口说明
判断两个WantAgent实例是否相等(callback形式) #### Notification.getSlotsByBundle(bundle: BundleOption)
- equal参数描述 - 接口说明
获取指定包的通知通道(Promise形式)
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | ---------------------- | ---- | --------------------------------------- | - getSlotsByBundle参数描述
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| otherAgent | 只读 | WantAgent | 是 | WantAgent对象 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| callback | 只读 | AsyncCallback<boolean> | 是 | 判断两个WantAgent实例是否相等的回调方法 | | ------ | -------- | ------------ | ---- | ---------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
- 返回值为void
- 返回值
- 示例
Promise<Array\<NotificationSlot\>>
```js
import wantAgent from '@ohos.wantAgent'; - 示例
import { OperationType, Flags } from '@ohos.wantagent';
```js
//wantAgent对象 var bundle = {
var WantAgent1; bundle:"bundleName1";
var WantAgent2; }
Notification.getSlotsByBundle(bundle).then((data) => {
//getWantAgent回调 console.info("==========================>getSlotsByBundleCallback=======================>");
function getWantAgentCallback(err, data) { });
console.info("==========================>getWantAgentCallback=======================>"); ```
if (err.code == 0) {
WantAgent1 = data;
WantAgent2 = data;
} else { #### Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>)
console.info('----getWantAgent failed!----');
} - 接口说明
}
//WantAgentInfo对象 获取指定包的通知通道数(Callback形式)
var wantAgentInfo = {
wants: [ - getSlotNumByBundle参数描述
{
deviceId: "deviceId", | 名称 | 读写属性 | 类型 | 必填 | 描述 |
bundleName: "com.neu.setResultOnAbilityResultTest1", | -------- | -------- | ------------------------- | ---- | ---------------------- |
abilityName: "com.example.test.MainAbility", | bundle | 只读 | BundleOption | 是 | 指定包信息 |
action: "action1", | callback | 只读 | AsyncCallback\<number\> | 是 | 获取通知通道数回调函数 |
entities: ["entity1"],
type: "MIMETYPE", - 返回值
uri: "key={true,true,false}",
parameters: void
{
mykey0: 2222, - 示例
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]", ```js
mykey3: "ssssssssssssssssssssssssss", function getSlotNumByBundle(err, data) {
mykey4: [false, true, false], console.info("==========================>getSlotNumByBundleCallback=======================>");
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], }
mykey6: true, var bundle = {
} bundle:"bundleName1";
} }
], Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);
operationType: OperationType.START_ABILITIES, ```
requestCode: 0,
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG]
}
#### Notification.getSlotNumByBundle(bundle: BundleOption)
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
- 接口说明
//cancel回调
function equalCallback(err, data) { 获取指定包的通知通道数(Promise形式)
console.info("==========================>equalCallback=======================>");
} - getSlotNumByBundle参数描述
wantAgent.equal(WantAgent1, WantAgent1, equalCallback)
``` | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
#### WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise<boolean> - 返回值
- 接口说明 Promise\<number\>
判断两个WantAgent实例是否相等(Promise形式) - 示例
- equal参数描述 ```js
var bundle = {
bundle:"bundleName1";
| 名称 | 读写属性 | 类型 | 必填 | 描述 | }
| ---------- | -------- | --------- | ---- | ------------- | Notification.getSlotNumByBundle(bundle).then((data) => {
| agent | 只读 | WantAgent | 是 | WantAgent对象 | console.info("==========================>getSlotNumByBundleCallback=======================>");
| otherAgent | 只读 | WantAgent | 是 | WantAgent对象 | });
```
-
返回值为Promise<boolean>
#### Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\<void\>)
- 示例
- 接口说明
```js
import wantAgent from '@ohos.wantAgent'; 删除指定通知(Callback形式)
import { OperationType, Flags } from '@ohos.wantagent';
- remove参数描述
//wantAgent对象
var WantAgent1; | 名称 | 读写属性 | 类型 | 必填 | 描述 |
var WantAgent2; | --------------- | -------- | --------------------- | ---- | -------------------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
//WantAgentInfo对象 | notificationKey | 只读 | NotificationKey | 是 | 通知键值 |
var wantAgentInfo = { | callback | 只读 | AsyncCallback\<void\> | 是 | 删除指定通知回调函数 |
wants: [
{ - NotificationKey类型说明
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1", | 名称 | 读写属性 | 类型 | 必填 | 描述 |
abilityName: "com.example.test.MainAbility", | ----- | -------- | ------ | ---- | -------- |
action: "action1", | id | 读、写 | number | 是 | 通知ID |
entities: ["entity1"], | label | 读、写 | string | 否 | 通知标签 |
type: "MIMETYPE",
uri: "key={true,true,false}", - 返回值
parameters:
{ void
mykey0: 2222,
mykey1: [1, 2, 3], - 示例
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss", ```js
mykey4: [false, true, false], function removeCallback(err) {
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], console.info("==========================>removeCallback=======================>");
mykey6: true, }
} var bundle = {
} bundle:"bundleName1";
], }
operationType: OperationType.START_ABILITIES, var notificationKey = {
requestCode: 0, id:0;
wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] label:"label";
} }
Notification.remove(bundle, notificationKey, removeCallback);
wantAgent.getWantAgent(wantAgentInfo).then((data) => { ```
console.info("==========================>getWantAgentCallback=======================>");
WantAgent = data;
});
#### Notification.remove(bundle: BundleOption, notificationKey: NotificationKey)
wantAgent.equal(WantAgent1, WantAgent2).then((data) => {
console.info("==========================>equalCallback=======================>"); - 接口说明
});
``` 删除指定通知(Promise形式)
- remove参数描述
#### | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| --------------- | -------- | --------------- | ---- | ---------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
| notificationKey | 只读 | NotificationKey | 是 | 通知键值 |
- 返回值
Promise\<void\>
- 示例
```js
var bundle = {
bundle:"bundleName1";
}
var notificationKey = {
id:0;
label:"label";
}
Notification.remove(bundle, notificationKey).then((void) => {
console.info("==========================>removeCallback=======================>");
});
```
#### Notification.remove(hashCode: string, callback: AsyncCallback\<void\>)
- 接口说明
删除指定通知(Callback形式)
- remove参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | -------------------- |
| hashCode | 只读 | string | 是 | 通知唯一ID |
| callback | 只读 | AsyncCallback\<void\> | 是 | 删除指定通知回调函数 |
- 返回值
void
- 示例
```js
function removeCallback(err) {
console.info("==========================>removeCallback=======================>");
}
Notification.remove(hashCode, removeCallback);
```
#### Notification.remove(hashCode: string)
- 接口说明
删除指定通知(Promise形式)
- remove参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ---------- | ---- | ---------- |
| hashCode | 只读 | string | 是 | 通知唯一ID |
- 返回值
Promise\<void\>
- 示例
```js
Notification.remove(hashCode).then((void) => {
console.info("==========================>removeCallback=======================>");
});
```
#### Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>)
- 接口说明
删除指定包的所有通知(Callback形式)
- removeAll参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | ---------------------------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
| callback | 只读 | AsyncCallback\<void\> | 是 | 删除指定包的所有通知回调函数 |
- 返回值
void
- 示例
```js
function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>");
}
var bundle = {
bundle:"bundleName1";
}
Notification.removeAll(bundle, removeAllCallback);
```
#### Notification.removeAll(callback: AsyncCallback\<void\>)
- 接口说明
删除所有通知(Callback形式)
- removeAll参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | -------------------- |
| callback | 只读 | AsyncCallback\<void\> | 是 | 删除所有通知回调函数 |
- 返回值
void
- 示例
```js
function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>");
}
Notification.removeAll(removeAllCallback);
```
#### Notification.removeAll(bundle?: BundleOption)
- 接口说明
删除所有通知(Promise形式)
- removeAll参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------ | -------- | ------------ | ---- | ---------- |
| bundle | 只读 | BundleOption | 否 | 指定包信息 |
- 返回值
Promise\<void\>
- 示例
```js
Notification.removeAll().then((void) => {
console.info("==========================>removeAllCallback=======================>");
});
```
#### Notification.getAllActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>)
- 接口说明
获取活动通知(Callback形式)
- getAllActiveNotifications参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ------------------------------------------- | ---- | -------------------- |
| callback | 只读 | AsyncCallback<Array\<NotificationRequest\>> | 是 | 获取活动通知回调函数 |
- 返回值
void
- 示例
```js
function getAllActiveNotificationsCallback(err, data) {
console.info("==========================>getAllActiveNotificationsCallback=======================>");
}
Notification.getAllActiveNotifications(getAllActiveNotificationsCallback);
```
#### Notification.getAllActiveNotifications()
- 接口说明
获取活动通知(Promise形式)
- getAllActiveNotifications参数描述
- 返回值
Promise\<Array\<NotificationRequest\>\>
- 示例
```js
Notification.getAllActiveNotifications().then((data) => {
console.info("==========================>getAllActiveNotificationsCallback=======================>");
});
```
#### Notification.getActiveNotificationCount(callback: AsyncCallback\<number\>)
- 接口说明
获取当前应用的活动通知数(Callback形式)
- getActiveNotificationCount参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ---------------------- | ---- | ---------------------- |
| callback | 只读 | AsyncCallback\<number\> | 是 | 获取活动通知数回调函数 |
- 返回值
void
- 示例
```js
function getActiveNotificationCountCallback(err, data) {
console.info("==========================>getActiveNotificationCountCallback=======================>");
}
Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
```
#### Notification.getActiveNotificationCount()
- 接口说明
获取当前应用的活动通知数(Promise形式)
- getActiveNotificationCount参数描述
- 返回值
返回值为Promise\<number\>
- 示例
```js
Notification.getActiveNotificationCount().then((data) => {
console.info("==========================>getActiveNotificationCountCallback=======================>");
});
```
#### Notification.getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>)
- 接口说明
获取当前应用的活动通知(Callback形式)
- getActiveNotifications参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ------------------------------------------- | ---- | ------------------------------ |
| callback | 只读 | AsyncCallback<Array\<NotificationRequest\>> | 是 | 获取当前应用的活动通知回调函数 |
- 返回值
void
- 示例
```js
function getActiveNotificationsCallback(err, data) {
console.info("==========================>getActiveNotificationsCallback=======================>");
}
Notification.getActiveNotifications(getActiveNotificationsCallback);
```
#### Notification.getActiveNotifications()
- 接口说明
获取当前应用的活动通知(Promise形式)
- getActiveNotifications参数描述
- 返回值
Promise\<Array\<NotificationRequest\>\>
- 示例
```js
Notification.getActiveNotifications().then((data) => {
console.info("==========================>getActiveNotificationsCallback=======================>");
});
```
#### Notification.cancelGroup(groupName: string, callback: AsyncCallback\<void\>)
- 接口说明
取消本应用指定组通知(Callback形式)
- cancelGroup参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| --------- | -------- | --------------------- | ---- | ---------------------------- |
| groupName | 只读 | string | 是 | 指定通知组名称 |
| callback | 只读 | AsyncCallback\<void\> | 是 | 取消本应用指定组通知回调函数 |
- 返回值
void
- 示例
```js
function cancelGroupCallback(err) {
console.info("==========================>cancelGroupCallback=======================>");
}
var groupName = "GroupName";
Notification.cancelGroup(groupName, cancelGroupCallback);
```
#### Notification.cancelGroup(groupName: string)
- 接口说明
取消本应用指定组通知(Promise形式)
- cancelGroup参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| --------- | -------- | ------ | ---- | -------------- |
| groupName | 只读 | string | 是 | 指定通知组名称 |
- 返回值
Promise\<void\>
- 示例
```js
var groupName = "GroupName";
Notification.cancelGroup(groupName).then(() => {
console.info("==========================>cancelGroupPromise=======================>");
});
```
#### Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>)
- 接口说明
删除指定应用指定组通知(Callback形式)
- removeGroupByBundle参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| --------- | -------- | --------------------- | ---- | ---------------------------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
| groupName | 只读 | string | 是 | 指定通知组名称 |
| callback | 只读 | AsyncCallback\<void\> | 是 | 删除本应用指定组通知回调函数 |
- 返回值
void
- 示例
```js
function removeGroupByBundleCallback(err) {
console.info("==========================>removeGroupByBundleCallback=======================>");
}
var bundleOption = {bundle:"Bundle"};
var groupName = "GroupName";
Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback);
```
#### Notification.removeGroupByBundle(bundle: BundleOption, groupName: string)
- 接口说明
删除指定应用指定组通知(Promise形式)
- removeGroupByBundle参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| --------- | -------- | ------------ | ---- | -------------- |
| bundle | 只读 | BundleOption | 是 | 指定包信息 |
| groupName | 只读 | string | 是 | 指定通知组名称 |
- 返回值
Promise\<void\>
- 示例
```js
var bundleOption = {bundle:"Bundle"};
var groupName = "GroupName";
Notification.removeGroupByBundle(bundleOption, groupName).then(() => {
console.info("==========================>removeGroupByBundlePromise=======================>");
});
```
#### Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>)
- 接口说明
设置免打扰时间(Callback形式)
- setDoNotDisturbDate参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | ---------------------- |
| date | 只读 | DoNotDisturbDate | 是 | 免打扰时间选项 |
| callback | 只读 | AsyncCallback\<void\> | 是 | 设置免打扰时间回调函数 |
- 返回值
void
- 示例
```js
function setDoNotDisturbDateCallback(err) {
console.info("==========================>setDoNotDisturbDateCallback=======================>");
}
var doNotDisturbDate = {
type : notification.DoNotDisturbType.TYPE_ONCE,
begin : new Date(),
end : new Date(2021, 11, 15, 18, 0)
}
Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback);
```
#### Notification.setDoNotDisturbDate(date: DoNotDisturbDate)
- 接口说明
设置免打扰时间接口(Promise形式)
- setDoNotDisturbDate参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---- | -------- | ---------------- | ---- | -------------- |
| date | 只读 | DoNotDisturbDate | 是 | 免打扰时间选项 |
- 返回值
Promise\<void\>
- 示例
```js
var doNotDisturbDate = {
type : notification.DoNotDisturbType.TYPE_ONCE,
begin : new Date(),
end : new Date(2021, 11, 15, 18, 0)
}
Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => {
console.info("==========================>setDoNotDisturbDatePromise=======================>");
});
```
#### Notification.getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>)
- 接口说明
查询免打扰时间接口(Callback形式)
- getDoNotDisturbDate参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------------------- | ---- | ---------------------- |
| callback | 只读 | AsyncCallback\<DoNotDisturbDate\> | 是 | 查询免打扰时间回调函数 |
- 返回值
void
- 示例
```js
function getDoNotDisturbDateCallback(err,data) {
console.info("==========================>getDoNotDisturbDateCallback=======================>");
}
Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback);
```
#### Notification.getDoNotDisturbDate()
- 接口说明
查询免打扰时间接口(Promise形式)
- getDoNotDisturbDate参数描述
- 返回值
Promise\<DoNotDisturbDate\>
- 示例
```js
Notification.getDoNotDisturbDate().then((data) => {
console.info("==========================>getDoNotDisturbDatePromise=======================>");
});
```
#### Notification.supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>)
- 接口说明
查询是否支持勿扰模式功能(Callback形式)
- supportDoNotDisturbMode参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ------------------------ | ---- | -------------------------------- |
| callback | 只读 | AsyncCallback\<boolean\> | 是 | 查询是否支持勿扰模式功能回调函数 |
- 返回值
void
- 示例
```js
function supportDoNotDisturbModeCallback(err,data) {
console.info("==========================>supportDoNotDisturbModeCallback=======================>");
}
Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback);
```
#### Notification.supportDoNotDisturbMode()
- 接口说明
查询是否支持勿扰模式功能(Promise形式)
- supportDoNotDisturbMode参数描述
- 返回值
Promise\<boolean\>
- 示例
```js
Notification.supportDoNotDisturbMode().then((data) => {
console.info("==========================>supportDoNotDisturbModePromise=======================>");
});
```
#### WantAgent接口
#### 导入模块
```js
import WantAgent from '@ohos.wantAgent';
```
#### WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>)
- 接口说明
创建WantAgent(callback形式)
- getWantAgent参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | -------------------------- | ---- | ----------------------- |
| info | 只读 | WantAgentInfo | 是 | WantAgent信息 |
| callback | 只读 | AsyncCallback\<WantAgent\> | 是 | 创建WantAgent的回调方法 |
- WantAgentInfo类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------------- | -------- | ------------------------------- | ---- | ---------------------- |
| wants | 读、写 | Array\<Want\> | 是 | 将被执行的动作列表 |
| operationType | 读、写 | wantAgent.OperationType | 是 | 动作类型 |
| requestCode | 读、写 | number | 是 | 使用者定义的一个私有值 |
| wantAgentFlags | 读、写 | Array<wantAgent.WantAgentFlags> | 否 | 动作执行属性 |
| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 |
-
WantAgentFlags类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------------------- | -------- | ---- | ---- | ------------------------------------------------------------ |
| ONE_TIME_FLAG | 只读 | enum | 否 | WantAgent仅能使用一次 |
| NO_BUILD_FLAG | 只读 | enum | 否 | 如果描述WantAgent对象不存在,则不创建它,直接返回null |
| CANCEL_PRESENT_FLAG | 只读 | enum | 否 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象 |
| UPDATE_PRESENT_FLAG | 只读 | enum | 否 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据 |
| CONSTANT_FLAG | 只读 | enum | 否 | WantAgent是不可变的 |
| REPLACE_ELEMENT | 只读 | enum | 否 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代 |
| REPLACE_ACTION | 只读 | enum | 否 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代 |
| REPLACE_URI | 只读 | enum | 否 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代 |
| REPLACE_ENTITIES | 只读 | enum | 否 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代 |
| REPLACE_BUNDLE | 只读 | enum | 否 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代 |
- OperationType类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----------------- | -------- | ---- | ---- | ----------------------- |
| UNKNOWN_TYPE | 只读 | enum | 否 | 不识别的类型 |
| START_ABILITY | 只读 | enum | 否 | 开启一个有页面的Ability |
| START_ABILITIES | 只读 | enum | 否 | 开启多个有页面的Ability |
| START_SERVICE | 只读 | enum | 否 | 开启一个无页面的ability |
| SEND_COMMON_EVENT | 只读 | enum | 否 | 发送一个公共事件 |
- 返回值
void
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
```
#### WantAgent.getWantAgent(info: WantAgentInfo): Promise\<WantAgent\>
- 接口说明
创建WantAgent(Promise形式)
- getWantAgent参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---- | -------- | ------------- | ---- | ------------- |
| info | 只读 | WantAgentInfo | 是 | WantAgent信息 |
- 返回值
Promise\<WantAgent\>
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
});
```
#### WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>)
- 接口说明
获取WantAgent实例的包名(callback形式)
- getBundleName参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ----------------------- | ---- | --------------------------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| callback | 只读 | AsyncCallback\<string\> | 是 | 获取WantAgent实例的包名的回调方法 |
- 返回值
void
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
WantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getBundleName回调
function getBundleNameCallback(err, data) {
console.info("==========================>getBundleNameCallback=======================>");
}
wantAgent.getBundleName(WantAgent, getBundleNameCallback)
```
#### WantAgent.getBundleName(agent: WantAgent): Promise\<string\>
- 接口说明
获取WantAgent实例的包名(Promise形式)
- getBundleName参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----- | -------- | --------- | ---- | ------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
- 返回值
Promise\<string\>
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
WantAgent = data;
});
wantAgent.getBundleName(WantAgent).then((data) => {
console.info("==========================>getBundleNameCallback=======================>");
});
```
#### WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\<number\>)
- 接口说明
获取WantAgent实例的用户ID(callback形式)
- getUid参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ----------------------- | ---- | ----------------------------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| callback | 只读 | AsyncCallback\<number\> | 是 | 获取WantAgent实例的用户ID的回调方法 |
- 返回值
void
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
WantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getUid回调
function getUidCallback(err, data) {
console.info("==========================>getUidCallback=======================>");
}
wantAgent.getUid(WantAgent, getUidCallback)
```
#### WantAgent.getUid(agent: WantAgent): Promise\<number\>
- 接口说明
获取WantAgent实例的用户ID(Promise形式)
- getUid参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----- | -------- | --------- | ---- | ------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
- 返回值
Promise\<number\>
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
WantAgent = data;
});
wantAgent.getUid(WantAgent).then((data) => {
console.info("==========================>getUidCallback=======================>");
});
```
#### WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\<Want\>)
- 接口说明
获取WantAgent对象的want(callback形式)
- getWant参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | ------------------------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| callback | 只读 | AsyncCallback\<Want\> | 是 | 获取WantAgent对象want的回调方法 |
- 返回值
void
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
WantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentWantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getWant回调
function getWantCallback(err, data) {
console.info("==========================>getWantCallback=======================>");
}
wantAgent.getWant(WantAgent, getWantCallback)
```
#### WantAgent.getWant(agent: WantAgent): Promise\<Want\>
- 接口说明
获取WantAgent对象的Uid(Promise形式)
- getWant参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----- | -------- | --------- | ---- | ------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
- 返回值
Promise\<Want\>
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
WantAgent = data;
});
wantAgent.getWant(WantAgent).then((data) => {
console.info("==========================>getWantCallback=======================>");
});
```
#### WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\<void\>)
- 接口说明
取消WantAgent实例(callback形式)
- cancel参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | --------------------- | ---- | --------------------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| callback | 只读 | AsyncCallback\<void\> | 是 | 取消WantAgent实例的回调方法 |
- 返回值
void
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
WantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//cancel回调
function cancelCallback(err, data) {
console.info("==========================>cancelCallback=======================>");
}
wantAgent.cancel(WantAgent, cancelCallback)
```
#### WantAgent.cancel(agent: WantAgent): Promise\<void\>
- 接口说明
取消WantAgent实例(Promise形式)
- cancel参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----- | -------- | --------- | ---- | ------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
- 返回值
Promise\<void\>
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
WantAgent = data;
});
wantAgent.cancel(WantAgent).then((data) => {
console.info("==========================>cancelCallback=======================>");
});
```
#### WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>)
- 接口说明
主动激发WantAgent实例(callback形式)
- trigger参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ----------- | -------- | ----------------------------- | ---- | ------------------------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| triggerInfo | 只读 | TriggerInfo | 是 | TriggerInfo对象 |
| callback | 只读 | AsyncCallback\<CompleteData\> | 是 | 主动激发WantAgent实例的回调方法 |
- TriggerInfo类型说明
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | -------------------- | ---- | ----------- |
| code | 读、写 | number | 是 | result code |
| want | 读、写 | Want | 否 | Want |
| permission | 读、写 | string | 否 | 权限定义 |
| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 |
- 返回值
void
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
WantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//trigger回调
function triggerCallback(err, data) {
console.info("==========================>triggerCallback=======================>");
}
var triggerInfo = {
code:0
}
wantAgent.trigger(WantAgent, triggerInfo, triggerCallback)
```
#### WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>)
- 接口说明
判断两个WantAgent实例是否相等(callback形式)
- equal参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | ------------------------ | ---- | --------------------------------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| otherAgent | 只读 | WantAgent | 是 | WantAgent对象 |
| callback | 只读 | AsyncCallback\<boolean\> | 是 | 判断两个WantAgent实例是否相等的回调方法 |
- 返回值
void
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent1;
var WantAgent2;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
WantAgent1 = data;
WantAgent2 = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//equal回调
function equalCallback(err, data) {
console.info("==========================>equalCallback=======================>");
}
wantAgent.equal(WantAgent1, WantAgent1, equalCallback)
```
#### WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>
- 接口说明
判断两个WantAgent实例是否相等(Promise形式)
- equal参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | --------- | ---- | ------------- |
| agent | 只读 | WantAgent | 是 | WantAgent对象 |
| otherAgent | 只读 | WantAgent | 是 | WantAgent对象 |
- 返回值
Promise\<boolean\>
- 示例
```js
import wantAgent from '@ohos.wantAgent';
import { OperationType, Flags } from '@ohos.wantagent';
//wantAgent对象
var WantAgent1;
var WantAgent2;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
wantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
WantAgent = data;
});
wantAgent.equal(WantAgent1, WantAgent2).then((data) => {
console.info("==========================>equalCallback=======================>");
});
```
####
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册