1# Notification模块(JS端SDK接口) 2 3#### 支持设备 4 5| API | 手机 | 平板 | 智慧屏 | 智能穿戴 | 6| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | 7| Notification.publish(request: NotificationRequest, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 8| Notification.publish(request: NotificationRequest) | 支持 | 支持 | 支持 | 支持 | 9| Notification.cancel(id: number, label: string, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 10| Notification.cancel(id:number, label?:string) | 支持 | 支持 | 支持 | 支持 | 11| Notification.cancel(id: number, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 12| Notification.cancelAll(callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 13| Notification.cancelAll() | 支持 | 支持 | 支持 | 支持 | 14| Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 15| Notification.addSlot(slot: NotificationSlot) | 支持 | 支持 | 支持 | 支持 | 16| Notification.addSlot(type: SlotType, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 17| Notification.addSlot(type: SlotType) | 支持 | 支持 | 支持 | 支持 | 18| Notification.addSlots(slots: Array<NotificationSlot>, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 19| Notification.addSlots(slots: Array<NotificationSlot>) | 支持 | 支持 | 支持 | 支持 | 20| Notification.getSlot(slotType: SlotType, callback: AsyncCallback<NotificationSlot>) | 支持 | 支持 | 支持 | 支持 | 21| Notification.getSlot(slotType: SlotType) | 支持 | 支持 | 支持 | 支持 | 22| Notification.getSlots(callback: AsyncCallback<Array<NotificationSlot>>) | 支持 | 支持 | 支持 | 支持 | 23| Notification.getSlots() | 支持 | 支持 | 支持 | 支持 | 24| Notification.removeSlot(slotType: SlotType, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 25| Notification.removeSlot(slotType: SlotType) | 支持 | 支持 | 支持 | 支持 | 26| Notification.removeAllSlots(callback: AsyncCallback<void>): void | 支持 | 支持 | 支持 | 支持 | 27| Notification.removeAllSlots(): Promise<void> | 支持 | 支持 | 支持 | 支持 | 28| Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 29| Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 30| Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) | 支持 | 支持 | 支持 | 支持 | 31| Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 32| Notification.unsubscribe(subscriber: NotificationSubscriber) | 支持 | 支持 | 支持 | 支持 | 33| Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 34| Notification.enableNotification(bundle: BundleOption, enable: boolean) | 支持 | 支持 | 支持 | 支持 | 35| Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback<boolean>) | 支持 | 支持 | 支持 | 支持 | 36| Notification.isNotificationEnabled(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 | 37| Notification.isNotificationEnabled(callback: AsyncCallback<boolean>) | 支持 | 支持 | 支持 | 支持 | 38| Notification.isNotificationEnabled() | 支持 | 支持 | 支持 | 支持 | 39| Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 40| Notification.displayBadge(bundle: BundleOption, enable: boolean) | 支持 | 支持 | 支持 | 支持 | 41| Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback<boolean>) | 支持 | 支持 | 支持 | 支持 | 42| Notification.isBadgeDisplayed(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 | 43| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 44| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) | 支持 | 支持 | 支持 | 支持 | 45| Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array<NotificationSlot>>) | 支持 | 支持 | 支持 | 支持 | 46| Notification.getSlotsByBundle(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 | 47| Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback<number>) | 支持 | 支持 | 支持 | 支持 | 48| Notification.getSlotNumByBundle(bundle: BundleOption) | 支持 | 支持 | 支持 | 支持 | 49| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 50| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) | 支持 | 支持 | 支持 | 支持 | 51| Notification.remove(hashCode: string, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 52| Notification.remove(hashCode: string) | 支持 | 支持 | 支持 | 支持 | 53| Notification.removeAll(bundle: BundleOption, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 54| Notification.removeAll(callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 55| Notification.removeAll(bundle?: BundleOption) | 支持 | 支持 | 支持 | 支持 | 56| Notification.getAllActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>) | 支持 | 支持 | 支持 | 支持 | 57| Notification.getAllActiveNotifications() | 支持 | 支持 | 支持 | 支持 | 58| Notification.getActiveNotificationCount(callback: AsyncCallback<number>) | 支持 | 支持 | 支持 | 支持 | 59| Notification.getActiveNotificationCount() | 支持 | 支持 | 支持 | 支持 | 60| Notification.getActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>) | 支持 | 支持 | 支持 | 支持 | 61| Notification.getActiveNotifications() | 支持 | 支持 | 支持 | 支持 | 62| WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>) | 支持 | 支持 | 支持 | 支持 | 63| WantAgent.getWantAgent(info: WantAgentInfo): Promise<WantAgent> | 支持 | 支持 | 支持 | 支持 | 64| WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback<string>) | 支持 | 支持 | 支持 | 支持 | 65| WantAgent.getBundleName(agent: WantAgent): Promise<string> | 支持 | 支持 | 支持 | 支持 | 66| WantAgent.getUid(agent: WantAgent, callback: AsyncCallback<number>) | 支持 | 支持 | 支持 | 支持 | 67| WantAgent.getUid(agent: WantAgent): Promise<number> | 支持 | 支持 | 支持 | 支持 | 68| WantAgent.getWant(agent: WantAgent, callback: AsyncCallback<Want>) | 支持 | 支持 | 支持 | 支持 | 69| WantAgent.getWant(agent: WantAgent): Promise<Want> | 支持 | 支持 | 支持 | 支持 | 70| WantAgent.cancel(agent: WantAgent, callback: AsyncCallback<void>) | 支持 | 支持 | 支持 | 支持 | 71| WantAgent.cancel(agent: WantAgent): Promise<void> | 支持 | 支持 | 支持 | 支持 | 72| WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>) | 支持 | 支持 | 支持 | 支持 | 73| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>) | 支持 | 支持 | 支持 | 支持 | 74| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise<boolean> | 支持 | 支持 | 支持 | 支持 | 75 76#### 权限列表 77 78无 79 80#### 通知接口 81 82#### 导入模块 83 84```js 85import notify from '@ohos.notification'; 86``` 87 88#### Notification.publish(request: NotificationRequest, callback: AsyncCallback<void>) 89 90- 接口说明 91 92 发布通知(callback形式) 93 94- publish参数描述 95 96 97| 名称 | 读写属性 | 类型 | 必填 | 描述 | 98| -------- | -------- | ------------------- | ---- | ------------------------------------------- | 99| request | 只读 | NotificationRequest | 是 | 设置要发布通知内容的NotificationRequest对象 | 100| callback | 只读 | AsyncCallback<void> | 是 | 被指定的回调方法 | 101 102- NotificationRequest类型说明 103 104| 名称 | 读写属性 | 类型 | 必填 | 描述 | 105| ----------------- | -------- | ------------------------------- | ---- | -------------------------- | 106| content | 读、写 | NotificationContent | 是 | 通知内容 | 107| id | 读、写 | number | 否 | 通知ID | 108| slotType | 读、写 | SlotType | 否 | 通道类型 | 109| isOngoing | 读、写 | boolean | 否 | 是否进行时通知 | 110| isUnremovable | 读、写 | boolean | 否 | 是否可移除 | 111| deliveryTime | 读、写 | number | 否 | 通知发送时间 | 112| tapDismissed | 读、写 | boolean | 否 | 通知是否自动清除 | 113| autoDeletedTime | 读、写 | number | 否 | 自动清除的时间 | 114| wantAgent | 读、写 | WantAgent | 否 | 点击跳转的WantAgent | 115| extraInfo | 读、写 | {[key: string]: any} | 否 | 扩展参数 | 116| color | 读、写 | number | 否 | 通知背景颜色 | 117| colorEnabled | 读、写 | boolean | 否 | 通知背景颜色是否使能 | 118| isAlertOnce | 读、写 | boolean | 否 | 设置是否仅有一次此通知警报 | 119| isStopwatch | 读、写 | boolean | 否 | 是否显示已用时间 | 120| isCountDown | 读、写 | boolean | 否 | 是否显示倒计时时间 | 121| isFloatingIcon | 读、写 | boolean | 否 | 是否显示状态栏图标 | 122| isFloatingIcon | 读、写 | boolean | 否 | 是否显示状态栏图标 | 123| label | 读、写 | string | 否 | 通知标签 | 124| badgeIconStyle | 读、写 | number | 否 | 通知角标类型 | 125| showDeliveryTime | 读、写 | boolean | 否 | 是否显示分发时间 | 126| actionButtons | 读、写 | Array<NotificationActionButton> | 否 | 通知按钮,最多两个按钮 | 127| smallIcon | 读、写 | PixelMap | 否 | 通知小图标 | 128| largeIcon | 读、写 | PixelMap | 否 | 通知大图标 | 129| creatorBundleName | 只读 | string | 否 | 创建通知的包名 | 130| creatorUid | 只读 | number | 否 | 创建通知的UID | 131| creatorPid | 只读 | number | 否 | 创建通知的PID | 132| hashCode | 只读 | string | 否 | 通知唯一标识 | 133| classification | 读、写 | string | 否 | 通知分类 | 134 135NotificationContent类型说明 136 137| 名称 | 读写属性 | 类型 | 必填 | 描述 | 138| ----------- | -------- | ---------------------------- | ---- | -------------- | 139| contentType | 读、写 | ContentType | 是 | 通知内容类型 | 140| normal | 读、写 | NotificationBasicContent | 否 | 通知基本内容 | 141| longText | 读、写 | NotificationLongTextContent | 否 | 通知长文本内容 | 142| multiLine | 读、写 | NotificationMultiLineContent | 否 | 通知多行内容 | 143 144- ContentType类型说明 145 146| 名称 | 读写属性 | 类型 | 描述 | 147| --------------------------------- | -------- | ----------- | ---------------- | 148| NOTIFICATION_CONTENT_BASIC_TEXT | 只读 | ContentType | 普通类型通知 | 149| NOTIFICATION_CONTENT_LONG_TEXT | 只读 | ContentType | 长文本类型通知 | 150| NOTIFICATION_CONTENT_PICTURE | 只读 | ContentType | 图片类型通知 | 151| NOTIFICATION_CONTENT_CONVERSATION | 只读 | ContentType | 社交类型通知 | 152| NOTIFICATION_CONTENT_MULTILINE | 只读 | ContentType | 多行文本类型通知 | 153 154- NotificationBasicContent类型说明 155 156| 名称 | 读写属性 | 类型 | 必填 | 描述 | 157| -------------- | -------- | ------ | ---- | -------------------------------- | 158| title | 读、写 | string | 是 | 通知标题 | 159| text | 读、写 | string | 是 | 通知内容 | 160| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | 161 162- NotificationLongTextContent类型说明 163 164| 名称 | 读写属性 | 类型 | 必填 | 描述 | 165| -------------- | -------- | ------ | ---- | -------------------------------- | 166| title | 读、写 | string | 是 | 通知标题 | 167| text | 读、写 | string | 是 | 通知内容 | 168| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | 169| longText | 读、写 | string | 是 | 通知的长文本 | 170| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | 171| expandedTitle | 读、写 | string | 是 | 通知展开时的标题 | 172 173- NotificationMultiLineContent类型说明 174 175| 名称 | 读写属性 | 类型 | 必填 | 描述 | 176| -------------- | -------- | ------------- | ---- | -------------------------------- | 177| title | 读、写 | string | 是 | 通知标题 | 178| text | 读、写 | string | 是 | 通知内容 | 179| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | 180| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | 181| longTitle | 读、写 | string | 是 | 通知展开时的标题 | 182| lines | 读、写 | Array<String> | 是 | 通知的多行文本 | 183 184- NotificationPictureContent类型说明 185 186| 名称 | 读写属性 | 类型 | 必填 | 描述 | 187| -------------- | -------- | -------------- | ---- | -------------------------------- | 188| title | 读、写 | string | 是 | 通知标题 | 189| text | 读、写 | string | 是 | 通知内容 | 190| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | 191| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | 192| expandedTitle | 读、写 | string | 是 | 通知展开时的标题 | 193| picture | 读、写 | image.PixelMap | 是 | 通知的图片内容 | 194 195- NotificationActionButton类型说明 196 197| 名称 | 读写属性 | 类型 | 必填 | 描述 | 198| --------- | -------- | -------------- | ---- | ------------------------- | 199| title | 读、写 | string | 是 | 按钮标题 | 200| wantAgent | 读、写 | wantAgent | 是 | 点击按钮时触发的WantAgent | 201| extras | 读、写 | Array<String> | 否 | 按钮扩展信息 | 202| icon | 读、写 | image.PixelMap | 否 | 按钮图标 | 203 204- 返回值 205 206 返回值为void 207 208- 示例 209 210```js 211//publish回调 212function publishCallback(err) { 213 console.info("==========================>publishCallback=======================>"); 214} 215//通知Request对象 216var notificationRequest = { 217 id: 1, 218 content: { 219 contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 220 normal: { 221 title: "test_title", 222 text: "test_text", 223 additionalText: "test_additionalText" 224 } 225 } 226} 227Notification.publish(notificationRequest, publishCallback) 228``` 229 230 231 232#### Notification.publish(request: NotificationRequest) 233 234- 接口说明 235 236 发布通知(Promise形式) 237 238- 返回值 239 240 返回值为Promise<**void**> 241 242- 示例 243 244```js 245//通知Request对象 246var notificationRequest = { 247 notificationId: 1, 248 content: { 249 contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 250 normal: { 251 title: "test_title", 252 text: "test_text", 253 additionalText: "test_additionalText" 254 } 255 } 256} 257Notification.publish(notificationRequest).then((void) => { 258 console.info("==========================>publishCallback=======================>"); 259}); 260 261``` 262 263 264 265#### Notification.cancel(id: number, label: string, callback: AsyncCallback<void>) 266 267- 接口说明 268 269 取消与指定id和label相匹配的已发布通知(callback形式) 270 271- cancel参数描述 272 273 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 274 | -------- | -------- | ------------------- | ---- | -------------------- | 275 | id | 只读 | number | 是 | 通知ID | 276 | lable | 只读 | string | 是 | 通知标签 | 277 | callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | 278 279- 返回值 280 281 返回值为void 282 283- 示例 284 285```js 286//cancel回调 287function cancelCallback(err) { 288 console.info("==========================>cancelCallback=======================>"); 289} 290Notification.cancel(0, "label", cancelCallback) 291``` 292 293 294 295#### Notification.cancel(id:number, label?:string) 296 297- 接口说明 298 299 取消与指定id相匹配的已发布通知,label可以指定也可以不指定(Promise形式) 300 301- cancel参数描述 302 303 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 304 | ----- | -------- | ------ | ---- | -------- | 305 | id | 只读 | number | 是 | 通知ID | 306 | lable | 只读 | string | 是 | 通知标签 | 307 308- 返回值 309 310 返回值为Promise<**void**> 311 312- 示例 313 314```js 315Notification.cancel(0).then((void) => { 316 console.info("==========================>cancelCallback=======================>"); 317}); 318``` 319 320 321 322#### Notification.cancel(id: number, callback: AsyncCallback<void>) 323 324- 接口说明 325 326 取消与指定id相匹配的已发布通知(callback形式) 327 328- cancel参数描述 329 330 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 331 | -------- | -------- | ------------------- | ---- | -------------------- | 332 | id | 只读 | number | 是 | 通知ID | 333 | callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | 334 335- 返回值 336 337 返回值为void 338 339- 示例 340 341```js 342//cancel回调 343function cancelCallback(err) { 344 console.info("==========================>cancelCallback=======================>"); 345} 346Notification.cancel(0, cancelCallback) 347``` 348 349 350 351#### Notification.cancelAll(callback: AsyncCallback<void>) 352 353- 接口说明 354 355 取消所有已发布的通知(callback形式) 356 357- cancelAll参数描述 358 359 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 360 | -------- | -------- | ------------------- | ---- | -------------------- | 361 | callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | 362 363- 返回值 364 365 返回值为void 366 367- 示例 368 369```js 370//cancel回调 371function cancelAllback(err) { 372 console.info("==========================>cancelAllback=======================>"); 373} 374Notification.cancelAll(cancelCallback) 375``` 376 377 378 379#### Notification.cancelAll() 380 381- 接口说明 382 383 取消所有已发布的通知(callback形式) 384 385- 参数描述 386 387 无参数 388 389- 返回值 390 391 返回值为void 392 393- 示例 394 395```js 396Notification.cancelAll().then((void) => { 397 console.info("==========================>cancelAllback=======================>"); 398}); 399``` 400 401#### Notification.addSlot(type: SlotType, callback: AsyncCallback<void>) 402 403- 接口说明 404 405 创建通知通道(callback形式) 406 407- addSlot参数描述 408 409 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 410 | -------- | -------- | ------------------- | ---- | ---------------------- | 411 | type | 只读 | SlotType | 是 | 要创建的通知通道的类型 | 412 | callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | 413 414- SlotType类型说明 415 416| 名称 | 读写属性 | 类型 | 必填 | 描述 | 417| -------------------- | -------- | -------- | ---- | -------- | 418| SOCIAL_COMMUNICATION | 只读 | SlotType | 否 | 社交类型 | 419| SERVICE_INFORMATION | 只读 | SlotType | 否 | 服务类型 | 420| CONTENT_INFORMATION | 只读 | SlotType | 否 | 内容类型 | 421| OTHER_TYPES | 只读 | SlotType | 否 | 其他类型 | 422 423* 返回值 424 425 返回值为void 426 427* 示例 428 429```js 430//addslot回调 431function addSlotCallBack(err) { 432 console.info("==========================>addSlotCallBack=======================>"); 433} 434Notification.addSlot(SOCIAL_COMMUNICATION, addSlotCallBack) 435``` 436 437 438 439#### Notification.addSlot(type: SlotType) 440 441- 接口说明 442 443 创建通知通道(Promise形式) 444 445- addSlot参数描述 446 447 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 448 | ---- | -------- | -------- | ---- | ---------------------- | 449 | type | 只读 | SlotType | 是 | 要创建的通知通道的类型 | 450 451- 返回值 452 453 返回值为Promise<**void**> 454 455- 示例 456 457```js 458Notification.addSlot(SOCIAL_COMMUNICATION).then((void) => { 459 console.info("==========================>addSlotCallback=======================>"); 460}); 461``` 462 463#### Notification.getSlot(slotType: SlotType, callback: AsyncCallback<NotificationSlot>) 464 465- 接口说明 466 467 获取一个通知通道(callback形式) 468 469- getSlot参数描述 470 471 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 472 | -------- | -------- | ------------------------------- | ---- | ----------------------------------------------------------- | 473 | slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | 474 | callback | 只读 | AsyncCallback<NotificationSlot> | 是 | 表示被指定的回调方法 | 475 476- 返回值 477 478 返回值为void 479 480- 示例 481 482```js 483//getSlot回调 484function getSlotCallback(err,data) { 485 console.info("==========================>getSlotCallback=======================>"); 486} 487var slotType = SOCIAL_COMMUNICATION; 488Notification.getSlot(slotType, getSlotCallback) 489``` 490 491 492 493#### Notification.getSlot(slotType) 494 495- 接口说明 496 497 获取一个通知通道(Promise形式) 498 499* getSlot参数描述 500 501 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 502 | -------- | -------- | -------- | ---- | ----------------------------------------------------------- | 503 | slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | 504 505* 返回值 506 507 返回值为Promise<NotificationSlot> 508 509* 示例 510 511```js 512var slotType = SOCIAL_COMMUNICATION; 513Notification.getSlot(slotType).then((data) => { 514 console.info("==========================>getSlotCallback=======================>"); 515``` 516 517 518 519#### Notification.getSlots(callback: AsyncCallback<Array<NotificationSlot>>) 520 521- 接口说明 522 523 获取此应用程序的所有通知通道(callback形式) 524 525- getSlots参数描述 526 527 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 528 | -------- | -------- | ------------------------------- | ---- | -------------------- | 529 | callback | 只读 | AsyncCallback<NotificationSlot> | 是 | 表示被指定的回调方法 | 530 531- 返回值 532 533 返回值为void 534 535- 示例 536 537```js 538//getSlots回调 539function getSlotsCallback(err,data) { 540 console.info("==========================>getSlotsCallback=======================>"); 541} 542Notification.getSlots(getSlotsCallback) 543``` 544 545 546 547#### Notification.getSlots() 548 549- 接口说明 550 551 获取此应用程序的所有通知通道(Promise形式) 552 553- getSlots参数描述 554 555 无参数 556 557- 返回值 558 559 返回值为Promise<Array<NotificationSlot>> 560 561- 示例 562 563```js 564Notification.getSlots().then((data) => { 565 console.info("==========================>getSlotsCallback=======================>"); 566``` 567 568 569 570#### Notification.removeSlot(slotType: SlotType, callback: AsyncCallback<void>) 571 572- 接口说明 573 574 根据通知通道类型删除创建的通知通道(callback形式) 575 576- removeSlot参数描述 577 578 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 579 | -------- | -------- | ------------------- | ---- | ----------------------------------------------------------- | 580 | SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | 581 | callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | 582 583- 584 585 返回值为void 586 587- 示例 588 589```js 590//removeSlot回调 591function removeSlotCallback(err) { 592 console.info("==========================>removeSlotCallback=======================>"); 593} 594var slotType = SOCIAL_COMMUNICATION; 595Notification.removeSlot(slotType,removeSlotCallback) 596``` 597 598 599 600#### Notification.removeSlot(slotType: SlotType) 601 602- 接口说明 603 604 根据通知通道类型删除创建的通知通道(Promise形式) 605 606- removeSlot参数描述 607 608 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 609 | -------- | -------- | -------- | ---- | ----------------------------------------------------------- | 610 | SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | 611 612- 613 614 返回值为Promise<**void**> 615 616- 示例 617 618```js 619var slotType = SOCIAL_COMMUNICATION; 620Notification.removeSlot(slotType).then((void) => { 621 console.info("==========================>removeSlotCallback=======================>"); 622``` 623 624 625 626#### Notification.removeAllSlots(callback: AsyncCallback<void>) 627 628- 接口说明 629 630 删除所有通知通道(callback形式) 631 632- removeAllSlots参数描述 633 634 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 635 | -------- | -------- | ------------------- | ---- | -------------------- | 636 | callback | 只读 | AsyncCallback<void> | 是 | 表示被指定的回调方法 | 637 638- 639 640 返回值为void 641 642- 示例 643 644```js 645function removeAllCallBack(err) { 646 console.info("================>removeAllCallBack=======================>"); 647} 648Notification.removeAllSlots(removeAllCallBack) 649``` 650 651 652 653#### Notification.removeAllSlots() 654 655- 接口说明 656 657 删除所有通知通道(Promise形式) 658 659- removeAllSlots参数描述 660 661 参数无 662 663- 664 665 返回值为Promise<**void**> 666 667- 示例 668 669```js 670 671Notification.removeAllSlots().then((void) => { 672 console.info("==========================>removeAllCallBack=======================>"); 673}); 674``` 675 676#### Notification.getAllActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>) 677 678- 接口说明 679 680 获取活动通知(Callback形式) 681 682- getAllActiveNotifications参数描述 683 684 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 685 | -------- | -------- | ----------------------------------------- | ---- | -------------------- | 686 | callback | 只读 | AsyncCallback<Array<NotificationRequest>> | 是 | 获取活动通知回调函数 | 687 688- 689 690 返回值为void 691 692- 示例 693 694```js 695function getAllActiveNotificationsCallback(err, data) { 696 console.info("==========================>getAllActiveNotificationsCallback=======================>"); 697} 698 699Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); 700``` 701 702 703 704#### Notification.getAllActiveNotifications() 705 706- 接口说明 707 708 获取活动通知(Promise形式) 709 710- getAllActiveNotifications参数描述 711 712 无 713 714- 715 716 返回值为Promise<Array<NotificationRequest>> 717 718- 示例 719 720```js 721Notification.getAllActiveNotifications().then((data) => { 722 console.info("==========================>getAllActiveNotificationsCallback=======================>"); 723}); 724``` 725 726 727 728#### Notification.getActiveNotificationCount(callback: AsyncCallback<**number**>) 729 730- 接口说明 731 732 获取当前应用的活动通知数(Callback形式) 733 734- getActiveNotificationCount参数描述 735 736 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 737 | -------- | -------- | ------------------------- | ---- | ---------------------- | 738 | callback | 只读 | AsyncCallback<**number**> | 是 | 获取活动通知数回调函数 | 739 740- 741 742 返回值为void 743 744- 示例 745 746```js 747function getActiveNotificationCountCallback(err, data) { 748 console.info("==========================>getActiveNotificationCountCallback=======================>"); 749} 750 751Notification.getActiveNotificationCount(getActiveNotificationCountCallback); 752``` 753 754 755 756#### Notification.getActiveNotificationCount() 757 758- 接口说明 759 760 获取当前应用的活动通知数(Promise形式) 761 762- getActiveNotificationCount参数描述 763 764 无 765 766- 767 768 返回值为Promise<**number**> 769 770- 示例 771 772```js 773Notification.getActiveNotificationCount().then((data) => { 774 console.info("==========================>getActiveNotificationCountCallback=======================>"); 775}); 776``` 777 778 779 780#### Notification.getActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>) 781 782- 接口说明 783 784 获取当前应用的活动通知(Callback形式) 785 786- getActiveNotifications参数描述 787 788 | 名称 | 读写属性 | 类型 | 必填 | 描述 | 789 | -------- | -------- | ----------------------------------------- | ---- | ------------------------------ | 790 | callback | 只读 | AsyncCallback<Array<NotificationRequest>> | 是 | 获取当前应用的活动通知回调函数 | 791 792- 793 794 返回值为void 795 796- 示例 797 798```js 799function getActiveNotificationsCallback(err, data) { 800 console.info("==========================>getActiveNotificationsCallback=======================>"); 801} 802 803Notification.getActiveNotifications(getActiveNotificationsCallback); 804``` 805 806 807 808#### Notification.getActiveNotifications() 809 810- 接口说明 811 812 获取当前应用的活动通知(Promise形式) 813 814- getActiveNotifications参数描述 815 816 无 817 818- 819 820 返回值为Promise<Array<NotificationRequest>> 821 822- 示例 823 824```js 825Notification.getActiveNotifications().then((data) => { 826 console.info("==========================>getActiveNotificationsCallback=======================>"); 827}); 828``` 829 830 831 832#### WantAgent接口 833 834#### 导入模块 835 836```js 837import WantAgent from '@ohos.wantAgent'; 838``` 839 840#### WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>) 841 842- 接口说明 843 844 创建WantAgent(callback形式) 845 846- getWantAgent参数描述 847 848 849| 名称 | 读写属性 | 类型 | 必填 | 描述 | 850| -------- | -------- | ------------------------ | ---- | ----------------------- | 851| info | 只读 | WantAgentInfo | 是 | WantAgent信息 | 852| callback | 只读 | AsyncCallback<WantAgent> | 是 | 创建WantAgent的回调方法 | 853 854- WantAgentInfo类型说明 855 856| 名称 | 读写属性 | 类型 | 必填 | 描述 | 857| -------------- | -------- | ------------------------------- | ---- | ---------------------- | 858| wants | 读、写 | Array<Want> | 是 | 将被执行的动作列表 | 859| operationType | 读、写 | wantAgent.OperationType | 是 | 动作类型 | 860| requestCode | 读、写 | number | 是 | 使用者定义的一个私有值 | 861| wantAgentFlags | 读、写 | Array<wantAgent.WantAgentFlags> | 否 | 动作执行属性 | 862| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 | 863 864- 865 WantAgentFlags类型说明 866 867 868| 名称 | 读写属性 | 类型 | 必填 | 描述 | 869| ------------------- | -------- | ---- | ---- | ------------------------------------------------------------ | 870| ONE_TIME_FLAG | 只读 | enum | 否 | WantAgent仅能使用一次 | 871| NO_BUILD_FLAG | 只读 | enum | 否 | 如果描述WantAgent对象不存在,则不创建它,直接返回null | 872| CANCEL_PRESENT_FLAG | 只读 | enum | 否 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象 | 873| UPDATE_PRESENT_FLAG | 只读 | enum | 否 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据 | 874| CONSTANT_FLAG | 只读 | enum | 否 | WantAgent是不可变的 | 875| REPLACE_ELEMENT | 只读 | enum | 否 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代 | 876| REPLACE_ACTION | 只读 | enum | 否 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代 | 877| REPLACE_URI | 只读 | enum | 否 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代 | 878| REPLACE_ENTITIES | 只读 | enum | 否 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代 | 879| REPLACE_BUNDLE | 只读 | enum | 否 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代 | 880 881- OperationType类型说明 882 883| 名称 | 读写属性 | 类型 | 必填 | 描述 | 884| ----------------- | -------- | ---- | ---- | ----------------------- | 885| UNKNOWN_TYPE | 只读 | enum | 否 | 不识别的类型 | 886| START_ABILITY | 只读 | enum | 否 | 开启一个有页面的Ability | 887| START_ABILITIES | 只读 | enum | 否 | 开启多个有页面的Ability | 888| START_SERVICE | 只读 | enum | 否 | 开启一个无页面的ability | 889| SEND_COMMON_EVENT | 只读 | enum | 否 | 发送一个公共事件 | 890 891- 892 893 返回值为void 894 895- 示例 896 897```js 898import wantAgent from '@ohos.wantAgent'; 899import { OperationType, Flags } from '@ohos.wantagent'; 900 901//getWantAgent回调 902function getWantAgentCallback(err, data) { 903 console.info("==========================>getWantAgentCallback=======================>"); 904} 905//WantAgentInfo对象 906var wantAgentInfo = { 907 wants: [ 908 { 909 deviceId: "deviceId", 910 bundleName: "com.neu.setResultOnAbilityResultTest1", 911 abilityName: "com.example.test.MainAbility", 912 action: "action1", 913 entities: ["entity1"], 914 type: "MIMETYPE", 915 uri: "key={true,true,false}", 916 parameters: 917 { 918 mykey0: 2222, 919 mykey1: [1, 2, 3], 920 mykey2: "[1, 2, 3]", 921 mykey3: "ssssssssssssssssssssssssss", 922 mykey4: [false, true, false], 923 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 924 mykey6: true, 925 } 926 } 927 ], 928 operationType: OperationType.START_ABILITIES, 929 requestCode: 0, 930 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 931} 932 933wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 934``` 935 936 937 938#### WantAgent.getWantAgent(info: WantAgentInfo): Promise<WantAgent> 939 940- 接口说明 941 942 创建WantAgent(Promise形式) 943 944- getWantAgent参数描述 945 946 947| 名称 | 读写属性 | 类型 | 必填 | 描述 | 948| ---- | -------- | ------------- | ---- | ------------- | 949| info | 只读 | WantAgentInfo | 是 | WantAgent信息 | 950 951- 952 953 返回值为Promise<WantAgent> 954 955- 示例 956 957```js 958import wantAgent from '@ohos.wantAgent'; 959import { OperationType, Flags } from '@ohos.wantagent'; 960 961//WantAgentInfo对象 962var wantAgentInfo = { 963 wants: [ 964 { 965 deviceId: "deviceId", 966 bundleName: "com.neu.setResultOnAbilityResultTest1", 967 abilityName: "com.example.test.MainAbility", 968 action: "action1", 969 entities: ["entity1"], 970 type: "MIMETYPE", 971 uri: "key={true,true,false}", 972 parameters: 973 { 974 mykey0: 2222, 975 mykey1: [1, 2, 3], 976 mykey2: "[1, 2, 3]", 977 mykey3: "ssssssssssssssssssssssssss", 978 mykey4: [false, true, false], 979 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 980 mykey6: true, 981 } 982 } 983 ], 984 operationType: OperationType.START_ABILITIES, 985 requestCode: 0, 986 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 987} 988 989wantAgent.getWantAgent(wantAgentInfo).then((data) => { 990 console.info("==========================>getWantAgentCallback=======================>"); 991}); 992``` 993 994 995 996#### WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback<string>) 997 998- 接口说明 999 1000 获取WantAgent实例的包名(callback形式) 1001 1002- getBundleName参数描述 1003 1004 1005| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1006| -------- | -------- | --------------------- | ---- | --------------------------------- | 1007| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1008| callback | 只读 | AsyncCallback<string> | 是 | 获取WantAgent实例的包名的回调方法 | 1009 1010- 返回值为void 1011 1012- 示例 1013 1014```js 1015import wantAgent from '@ohos.wantAgent'; 1016import { OperationType, Flags } from '@ohos.wantagent'; 1017 1018//wantAgent对象 1019var WantAgent; 1020 1021//getWantAgent回调 1022function getWantAgentCallback(err, data) { 1023 console.info("==========================>getWantAgentCallback=======================>"); 1024 if (err.code == 0) { 1025 WantAgent = data; 1026 } else { 1027 console.info('----getWantAgent failed!----'); 1028 } 1029} 1030//WantAgentInfo对象 1031var wantAgentInfo = { 1032 wants: [ 1033 { 1034 deviceId: "deviceId", 1035 bundleName: "com.neu.setResultOnAbilityResultTest1", 1036 abilityName: "com.example.test.MainAbility", 1037 action: "action1", 1038 entities: ["entity1"], 1039 type: "MIMETYPE", 1040 uri: "key={true,true,false}", 1041 parameters: 1042 { 1043 mykey0: 2222, 1044 mykey1: [1, 2, 3], 1045 mykey2: "[1, 2, 3]", 1046 mykey3: "ssssssssssssssssssssssssss", 1047 mykey4: [false, true, false], 1048 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1049 mykey6: true, 1050 } 1051 } 1052 ], 1053 operationType: OperationType.START_ABILITIES, 1054 requestCode: 0, 1055 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1056} 1057 1058wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 1059 1060//getBundleName回调 1061function getBundleNameCallback(err, data) { 1062 console.info("==========================>getBundleNameCallback=======================>"); 1063} 1064wantAgent.getBundleName(WantAgent, getBundleNameCallback) 1065``` 1066 1067 1068 1069#### WantAgent.getBundleName(agent: WantAgent): Promise<string> 1070 1071- 接口说明 1072 1073 获取WantAgent实例的包名(Promise形式) 1074 1075- getBundleName参数描述 1076 1077 1078| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1079| ----- | -------- | --------- | ---- | ------------- | 1080| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1081 1082- 1083 1084 返回值为Promise<string> 1085 1086- 示例 1087 1088```js 1089import wantAgent from '@ohos.wantAgent'; 1090import { OperationType, Flags } from '@ohos.wantagent'; 1091 1092//wantAgent对象 1093var WantAgent; 1094 1095//WantAgentInfo对象 1096var wantAgentInfo = { 1097 wants: [ 1098 { 1099 deviceId: "deviceId", 1100 bundleName: "com.neu.setResultOnAbilityResultTest1", 1101 abilityName: "com.example.test.MainAbility", 1102 action: "action1", 1103 entities: ["entity1"], 1104 type: "MIMETYPE", 1105 uri: "key={true,true,false}", 1106 parameters: 1107 { 1108 mykey0: 2222, 1109 mykey1: [1, 2, 3], 1110 mykey2: "[1, 2, 3]", 1111 mykey3: "ssssssssssssssssssssssssss", 1112 mykey4: [false, true, false], 1113 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1114 mykey6: true, 1115 } 1116 } 1117 ], 1118 operationType: OperationType.START_ABILITIES, 1119 requestCode: 0, 1120 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1121} 1122 1123wantAgent.getWantAgent(wantAgentInfo).then((data) => { 1124 console.info("==========================>getWantAgentCallback=======================>"); 1125 WantAgent = data; 1126}); 1127 1128wantAgent.getBundleName(WantAgent).then((data) => { 1129 console.info("==========================>getBundleNameCallback=======================>"); 1130}); 1131``` 1132 1133 1134 1135#### WantAgent.getUid(agent: WantAgent, callback: AsyncCallback<number>) 1136 1137- 接口说明 1138 1139 获取WantAgent实例的用户ID(callback形式) 1140 1141- getUid参数描述 1142 1143 1144| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1145| -------- | -------- | --------------------- | ---- | ----------------------------------- | 1146| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1147| callback | 只读 | AsyncCallback<number> | 是 | 获取WantAgent实例的用户ID的回调方法 | 1148 1149- 返回值为void 1150 1151- 示例 1152 1153```js 1154import wantAgent from '@ohos.wantAgent'; 1155import { OperationType, Flags } from '@ohos.wantagent'; 1156 1157//wantAgent对象 1158var WantAgent; 1159 1160//getWantAgent回调 1161function getWantAgentCallback(err, data) { 1162 console.info("==========================>getWantAgentCallback=======================>"); 1163 if (err.code == 0) { 1164 WantAgent = data; 1165 } else { 1166 console.info('----getWantAgent failed!----'); 1167 } 1168} 1169//WantAgentInfo对象 1170var wantAgentInfo = { 1171 wants: [ 1172 { 1173 deviceId: "deviceId", 1174 bundleName: "com.neu.setResultOnAbilityResultTest1", 1175 abilityName: "com.example.test.MainAbility", 1176 action: "action1", 1177 entities: ["entity1"], 1178 type: "MIMETYPE", 1179 uri: "key={true,true,false}", 1180 parameters: 1181 { 1182 mykey0: 2222, 1183 mykey1: [1, 2, 3], 1184 mykey2: "[1, 2, 3]", 1185 mykey3: "ssssssssssssssssssssssssss", 1186 mykey4: [false, true, false], 1187 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1188 mykey6: true, 1189 } 1190 } 1191 ], 1192 operationType: OperationType.START_ABILITIES, 1193 requestCode: 0, 1194 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1195} 1196 1197wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 1198 1199//getUid回调 1200function getUidCallback(err, data) { 1201 console.info("==========================>getUidCallback=======================>"); 1202} 1203wantAgent.getUid(WantAgent, getUidCallback) 1204``` 1205 1206 1207 1208#### WantAgent.getUid(agent: WantAgent): Promise<number> 1209 1210- 接口说明 1211 1212 获取WantAgent实例的用户ID(Promise形式) 1213 1214- getUid参数描述 1215 1216 1217| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1218| ----- | -------- | --------- | ---- | ------------- | 1219| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1220 1221- 1222 1223 返回值为Promise<number> 1224 1225- 示例 1226 1227```js 1228import wantAgent from '@ohos.wantAgent'; 1229import { OperationType, Flags } from '@ohos.wantagent'; 1230 1231//wantAgent对象 1232var WantAgent; 1233 1234//WantAgentInfo对象 1235var wantAgentInfo = { 1236 wants: [ 1237 { 1238 deviceId: "deviceId", 1239 bundleName: "com.neu.setResultOnAbilityResultTest1", 1240 abilityName: "com.example.test.MainAbility", 1241 action: "action1", 1242 entities: ["entity1"], 1243 type: "MIMETYPE", 1244 uri: "key={true,true,false}", 1245 parameters: 1246 { 1247 mykey0: 2222, 1248 mykey1: [1, 2, 3], 1249 mykey2: "[1, 2, 3]", 1250 mykey3: "ssssssssssssssssssssssssss", 1251 mykey4: [false, true, false], 1252 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1253 mykey6: true, 1254 } 1255 } 1256 ], 1257 operationType: OperationType.START_ABILITIES, 1258 requestCode: 0, 1259 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1260} 1261 1262wantAgent.getWantAgent(wantAgentInfo).then((data) => { 1263 console.info("==========================>getWantAgentCallback=======================>"); 1264 WantAgent = data; 1265}); 1266 1267wantAgent.getUid(WantAgent).then((data) => { 1268 console.info("==========================>getUidCallback=======================>"); 1269}); 1270``` 1271 1272 1273 1274#### WantAgent.cancel(agent: WantAgent, callback: AsyncCallback<void>) 1275 1276- 接口说明 1277 1278 取消WantAgent实例(callback形式) 1279 1280- cancel参数描述 1281 1282 1283| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1284| -------- | -------- | ------------------- | ---- | --------------------------- | 1285| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1286| callback | 只读 | AsyncCallback<void> | 是 | 取消WantAgent实例的回调方法 | 1287 1288- 返回值为void 1289 1290- 示例 1291 1292```js 1293import wantAgent from '@ohos.wantAgent'; 1294import { OperationType, Flags } from '@ohos.wantagent'; 1295 1296//wantAgent对象 1297var WantAgent; 1298 1299//getWantAgent回调 1300function getWantAgentCallback(err, data) { 1301 console.info("==========================>getWantAgentCallback=======================>"); 1302 if (err.code == 0) { 1303 WantAgent = data; 1304 } else { 1305 console.info('----getWantAgent failed!----'); 1306 } 1307} 1308//WantAgentInfo对象 1309var wantAgentInfo = { 1310 wants: [ 1311 { 1312 deviceId: "deviceId", 1313 bundleName: "com.neu.setResultOnAbilityResultTest1", 1314 abilityName: "com.example.test.MainAbility", 1315 action: "action1", 1316 entities: ["entity1"], 1317 type: "MIMETYPE", 1318 uri: "key={true,true,false}", 1319 parameters: 1320 { 1321 mykey0: 2222, 1322 mykey1: [1, 2, 3], 1323 mykey2: "[1, 2, 3]", 1324 mykey3: "ssssssssssssssssssssssssss", 1325 mykey4: [false, true, false], 1326 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1327 mykey6: true, 1328 } 1329 } 1330 ], 1331 operationType: OperationType.START_ABILITIES, 1332 requestCode: 0, 1333 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1334} 1335 1336wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 1337 1338//cancel回调 1339function cancelCallback(err, data) { 1340 console.info("==========================>cancelCallback=======================>"); 1341} 1342wantAgent.cancel(WantAgent, cancelCallback) 1343``` 1344 1345 1346 1347#### WantAgent.cancel(agent: WantAgent): Promise<void> 1348 1349- 接口说明 1350 1351 取消WantAgent实例(Promise形式) 1352 1353- cancel参数描述 1354 1355 1356| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1357| ----- | -------- | --------- | ---- | ------------- | 1358| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1359 1360- 1361 1362 返回值为Promise<void> 1363 1364- 示例 1365 1366```js 1367import wantAgent from '@ohos.wantAgent'; 1368import { OperationType, Flags } from '@ohos.wantagent'; 1369 1370//wantAgent对象 1371var WantAgent; 1372 1373//WantAgentInfo对象 1374var wantAgentInfo = { 1375 wants: [ 1376 { 1377 deviceId: "deviceId", 1378 bundleName: "com.neu.setResultOnAbilityResultTest1", 1379 abilityName: "com.example.test.MainAbility", 1380 action: "action1", 1381 entities: ["entity1"], 1382 type: "MIMETYPE", 1383 uri: "key={true,true,false}", 1384 parameters: 1385 { 1386 mykey0: 2222, 1387 mykey1: [1, 2, 3], 1388 mykey2: "[1, 2, 3]", 1389 mykey3: "ssssssssssssssssssssssssss", 1390 mykey4: [false, true, false], 1391 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1392 mykey6: true, 1393 } 1394 } 1395 ], 1396 operationType: OperationType.START_ABILITIES, 1397 requestCode: 0, 1398 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1399} 1400 1401wantAgent.getWantAgent(wantAgentInfo).then((data) => { 1402 console.info("==========================>getWantAgentCallback=======================>"); 1403 WantAgent = data; 1404}); 1405 1406wantAgent.cancel(WantAgent).then((data) => { 1407 console.info("==========================>cancelCallback=======================>"); 1408}); 1409``` 1410 1411 1412 1413#### WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>) 1414 1415- 接口说明 1416 1417 主动激发WantAgent实例(callback形式) 1418 1419- trigger参数描述 1420 1421 1422| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1423| ----------- | -------- | --------------------------- | ---- | ------------------------------- | 1424| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1425| triggerInfo | 只读 | TriggerInfo | 是 | TriggerInfo对象 | 1426| callback | 只读 | AsyncCallback<CompleteData> | 是 | 主动激发WantAgent实例的回调方法 | 1427 1428- TriggerInfo类型说明 1429 1430| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1431| ---------- | -------- | -------------------- | ---- | ----------- | 1432| code | 读、写 | number | 是 | result code | 1433| want | 读、写 | Want | 否 | Want | 1434| permission | 读、写 | string | 否 | 权限定义 | 1435| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 | 1436 1437- 返回值为void 1438- 示例 1439 1440```js 1441import wantAgent from '@ohos.wantAgent'; 1442import { OperationType, Flags } from '@ohos.wantagent'; 1443 1444//wantAgent对象 1445var WantAgent; 1446 1447//getWantAgent回调 1448function getWantAgentCallback(err, data) { 1449 console.info("==========================>getWantAgentCallback=======================>"); 1450 if (err.code == 0) { 1451 WantAgent = data; 1452 } else { 1453 console.info('----getWantAgent failed!----'); 1454 } 1455} 1456//WantAgentInfo对象 1457var wantAgentInfo = { 1458 wants: [ 1459 { 1460 deviceId: "deviceId", 1461 bundleName: "com.neu.setResultOnAbilityResultTest1", 1462 abilityName: "com.example.test.MainAbility", 1463 action: "action1", 1464 entities: ["entity1"], 1465 type: "MIMETYPE", 1466 uri: "key={true,true,false}", 1467 parameters: 1468 { 1469 mykey0: 2222, 1470 mykey1: [1, 2, 3], 1471 mykey2: "[1, 2, 3]", 1472 mykey3: "ssssssssssssssssssssssssss", 1473 mykey4: [false, true, false], 1474 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1475 mykey6: true, 1476 } 1477 } 1478 ], 1479 operationType: OperationType.START_ABILITIES, 1480 requestCode: 0, 1481 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1482} 1483 1484wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 1485 1486//cancel回调 1487function triggerCallback(err, data) { 1488 console.info("==========================>triggerCallback=======================>"); 1489} 1490wantAgent.trigger(WantAgent, triggerCallback) 1491``` 1492 1493 1494 1495#### WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>) 1496 1497- 接口说明 1498 1499 判断两个WantAgent实例是否相等(callback形式) 1500 1501- equal参数描述 1502 1503 1504| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1505| ---------- | -------- | ---------------------- | ---- | --------------------------------------- | 1506| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1507| otherAgent | 只读 | WantAgent | 是 | WantAgent对象 | 1508| callback | 只读 | AsyncCallback<boolean> | 是 | 判断两个WantAgent实例是否相等的回调方法 | 1509 1510- 返回值为void 1511 1512- 示例 1513 1514```js 1515import wantAgent from '@ohos.wantAgent'; 1516import { OperationType, Flags } from '@ohos.wantagent'; 1517 1518//wantAgent对象 1519var WantAgent1; 1520var WantAgent2; 1521 1522//getWantAgent回调 1523function getWantAgentCallback(err, data) { 1524 console.info("==========================>getWantAgentCallback=======================>"); 1525 if (err.code == 0) { 1526 WantAgent1 = data; 1527 WantAgent2 = data; 1528 } else { 1529 console.info('----getWantAgent failed!----'); 1530 } 1531} 1532//WantAgentInfo对象 1533var wantAgentInfo = { 1534 wants: [ 1535 { 1536 deviceId: "deviceId", 1537 bundleName: "com.neu.setResultOnAbilityResultTest1", 1538 abilityName: "com.example.test.MainAbility", 1539 action: "action1", 1540 entities: ["entity1"], 1541 type: "MIMETYPE", 1542 uri: "key={true,true,false}", 1543 parameters: 1544 { 1545 mykey0: 2222, 1546 mykey1: [1, 2, 3], 1547 mykey2: "[1, 2, 3]", 1548 mykey3: "ssssssssssssssssssssssssss", 1549 mykey4: [false, true, false], 1550 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1551 mykey6: true, 1552 } 1553 } 1554 ], 1555 operationType: OperationType.START_ABILITIES, 1556 requestCode: 0, 1557 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1558} 1559 1560wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 1561 1562//cancel回调 1563function equalCallback(err, data) { 1564 console.info("==========================>equalCallback=======================>"); 1565} 1566wantAgent.equal(WantAgent1, WantAgent1, equalCallback) 1567``` 1568 1569 1570 1571#### WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise<boolean> 1572 1573- 接口说明 1574 1575 判断两个WantAgent实例是否相等(Promise形式) 1576 1577- equal参数描述 1578 1579 1580| 名称 | 读写属性 | 类型 | 必填 | 描述 | 1581| ---------- | -------- | --------- | ---- | ------------- | 1582| agent | 只读 | WantAgent | 是 | WantAgent对象 | 1583| otherAgent | 只读 | WantAgent | 是 | WantAgent对象 | 1584 1585- 1586 1587 返回值为Promise<boolean> 1588 1589- 示例 1590 1591```js 1592import wantAgent from '@ohos.wantAgent'; 1593import { OperationType, Flags } from '@ohos.wantagent'; 1594 1595//wantAgent对象 1596var WantAgent1; 1597var WantAgent2; 1598 1599//WantAgentInfo对象 1600var wantAgentInfo = { 1601 wants: [ 1602 { 1603 deviceId: "deviceId", 1604 bundleName: "com.neu.setResultOnAbilityResultTest1", 1605 abilityName: "com.example.test.MainAbility", 1606 action: "action1", 1607 entities: ["entity1"], 1608 type: "MIMETYPE", 1609 uri: "key={true,true,false}", 1610 parameters: 1611 { 1612 mykey0: 2222, 1613 mykey1: [1, 2, 3], 1614 mykey2: "[1, 2, 3]", 1615 mykey3: "ssssssssssssssssssssssssss", 1616 mykey4: [false, true, false], 1617 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 1618 mykey6: true, 1619 } 1620 } 1621 ], 1622 operationType: OperationType.START_ABILITIES, 1623 requestCode: 0, 1624 wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] 1625} 1626 1627wantAgent.getWantAgent(wantAgentInfo).then((data) => { 1628 console.info("==========================>getWantAgentCallback=======================>"); 1629 WantAgent = data; 1630}); 1631 1632wantAgent.equal(WantAgent1, WantAgent2).then((data) => { 1633 console.info("==========================>equalCallback=======================>"); 1634}); 1635``` 1636 1637 1638 1639#### 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675