1# @ohos.app.ability.wantAgent (WantAgent模块) 2 3app.ability.WantAgent是一个封装了[Want](./js-apis-app-ability-want.md)对象的类,允许应用程序能够在未来的某个时间点执行该Want。该模块提供了创建WantAgent实例、获取实例的用户ID、获取want信息、比较WantAgent实例和获取包名等功能。 4WantAgent的一个典型应用场景是通知处理。例如,当用户点击通知时,会触发WantAgent的[trigger](#wantagenttrigger)接口,并拉起目标应用。具体使用请参考[通知模块](../../notification/notification-with-wantagent.md)。该模块将会取代[@ohos.wantAgent](js-apis-wantAgent.md)模块,建议优先使用本模块。 5 6> **说明:** 7> 8> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 9 10## 导入模块 11 12```ts 13import { wantAgent } from '@kit.AbilityKit'; 14``` 15 16## wantAgent.getWantAgent 17 18getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void 19 20创建WantAgent(callback形式)。 创建失败返回的WantAgent为空值。 21 22三方应用只能设置自己应用的Ability。 23 24**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 25 26**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 27 28**参数:** 29 30| 参数名 | 类型 | 必填 | 说明 | 31| -------- | -------------------------- | ---- | ----------------------- | 32| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是 | WantAgent信息。 | 33| callback | AsyncCallback\<WantAgent\> | 是 | 创建WantAgent的回调方法。 | 34 35**错误码:** 36 37以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 38 39| 错误码ID | 错误信息 | 40|-----------|--------------------| 41| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 42| 16000007 | Service busy. There are concurrent tasks. Try again later. | 43| 16000151 | Invalid wantagent object.| 44 45**示例:** 46 47```ts 48import { wantAgent, Want } from '@kit.AbilityKit'; 49import type { WantAgent } from '@kit.AbilityKit'; 50import { BusinessError } from '@kit.BasicServicesKit'; 51 52//wantAgent对象 53let wantAgentData: WantAgent; 54//WantAgentInfo对象 55let wantAgentInfo: wantAgent.WantAgentInfo = { 56 wants: [ 57 { 58 deviceId: 'deviceId', 59 bundleName: 'com.example.myapplication', 60 abilityName: 'EntryAbility', 61 action: 'action1', 62 entities: ['entity1'], 63 type: 'MIMETYPE', 64 uri: 'key={true,true,false}', 65 parameters: 66 { 67 mykey0: 2222, 68 mykey1: [1, 2, 3], 69 mykey2: '[1, 2, 3]', 70 mykey3: 'ssssssssssssssssssssssssss', 71 mykey4: [false, true, false], 72 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 73 mykey6: true, 74 } 75 } as Want 76 ], 77 actionType: wantAgent.OperationType.START_ABILITY, 78 requestCode: 0, 79 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 80}; 81 82//getWantAgent回调 83function getWantAgentCallback(err: BusinessError, data: WantAgent) { 84 if (err) { 85 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 86 } else { 87 wantAgentData = data; 88 } 89} 90 91try { 92 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 93} catch (err) { 94 console.error(`getWantAgent failed, error: ${JSON.stringify(err)}`); 95} 96``` 97 98## wantAgent.getWantAgent 99 100getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> 101 102创建WantAgent(Promise形式)。 创建失败返回的WantAgent为空值。 103 104三方应用只能设置自己应用的Ability。 105 106**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 107 108**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 109 110**参数:** 111 112| 参数名 | 类型 | 必填 | 说明 | 113| ---- | ------------- | ---- | ------------- | 114| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是 | WantAgent信息。 | 115 116**返回值:** 117 118| 类型 | 说明 | 119| ----------------------------------------------------------- | ------------------------------------------------------------ | 120| Promise\<WantAgent\> | 以Promise形式返回WantAgent。 | 121 122**错误码:** 123 124以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 125 126| 错误码ID | 错误信息 | 127|-----------|--------------------| 128| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 129| 16000007 | Service busy. There are concurrent tasks. Try again later. | 130| 16000151 | Invalid wantagent object.| 131 132**示例:** 133 134```ts 135import { wantAgent, Want } from '@kit.AbilityKit'; 136import type { WantAgent } from '@kit.AbilityKit'; 137import { BusinessError } from '@kit.BasicServicesKit'; 138 139let wantAgentData: WantAgent; 140//WantAgentInfo对象 141let wantAgentInfo: wantAgent.WantAgentInfo = { 142 wants: [ 143 { 144 deviceId: 'deviceId', 145 bundleName: 'com.example.myapplication', 146 abilityName: 'EntryAbility', 147 action: 'action1', 148 entities: ['entity1'], 149 type: 'MIMETYPE', 150 uri: 'key={true,true,false}', 151 parameters: 152 { 153 mykey0: 2222, 154 mykey1: [1, 2, 3], 155 mykey2: '[1, 2, 3]', 156 mykey3: 'ssssssssssssssssssssssssss', 157 mykey4: [false, true, false], 158 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 159 mykey6: true, 160 } 161 } as Want 162 ], 163 actionType: wantAgent.OperationType.START_ABILITY, 164 requestCode: 0, 165 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 166}; 167 168try { 169 wantAgent.getWantAgent(wantAgentInfo).then((data) => { 170 wantAgentData = data; 171 }).catch((err: BusinessError) => { 172 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 173 }); 174} catch (err) { 175 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 176} 177``` 178 179 180 181## wantAgent.getBundleName 182 183getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void 184 185获取WantAgent实例的包名(callback形式)。 186 187**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 188 189**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 190 191**参数:** 192 193| 参数名 | 类型 | 必填 | 说明 | 194| -------- | ----------------------- | ---- | --------------------------------- | 195| agent | WantAgent | 是 | WantAgent对象。 | 196| callback | AsyncCallback\<string\> | 是 | 获取WantAgent实例的包名的回调方法。 | 197 198**错误码:** 199 200以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 201 202| 错误码ID | 错误信息 | 203|-----------|--------------------| 204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 205| 16000007 | Service busy. There are concurrent tasks. Try again later. | 206| 16000151 | Invalid wantagent object.| 207 208**示例:** 209 210```ts 211import { wantAgent, Want } from '@kit.AbilityKit'; 212import type { WantAgent } from '@kit.AbilityKit'; 213import { BusinessError } from '@kit.BasicServicesKit'; 214 215//wantAgent对象 216let wantAgentData: WantAgent; 217//WantAgentInfo对象 218let wantAgentInfo: wantAgent.WantAgentInfo = { 219 wants: [ 220 { 221 deviceId: 'deviceId', 222 bundleName: 'com.example.myapplication', 223 abilityName: 'EntryAbility', 224 action: 'action1', 225 entities: ['entity1'], 226 type: 'MIMETYPE', 227 uri: 'key={true,true,false}', 228 parameters: 229 { 230 mykey0: 2222, 231 mykey1: [1, 2, 3], 232 mykey2: '[1, 2, 3]', 233 mykey3: 'ssssssssssssssssssssssssss', 234 mykey4: [false, true, false], 235 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 236 mykey6: true, 237 } 238 } as Want 239 ], 240 actionType: wantAgent.OperationType.START_ABILITY, 241 requestCode: 0, 242 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 243}; 244 245//getWantAgent回调 246function getWantAgentCallback(err: BusinessError, data: WantAgent) { 247 if (err) { 248 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 249 } else { 250 wantAgentData = data; 251 } 252 //getBundleName回调 253 let getBundleNameCallback = (err: BusinessError, data: string) => { 254 if (err) { 255 console.error(`getBundleName failed! ${err.code} ${err.message}`); 256 } else { 257 console.info(`getBundleName ok! ${JSON.stringify(data)}`); 258 } 259 } 260 try { 261 wantAgent.getBundleName(wantAgentData, getBundleNameCallback); 262 } catch (err) { 263 console.error(`getBundleName failed! ${err.code} ${err.message}`); 264 } 265} 266 267try { 268 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 269} catch (err) { 270 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 271} 272``` 273 274## wantAgent.getBundleName 275 276getBundleName(agent: WantAgent): Promise\<string\> 277 278获取WantAgent实例的包名(Promise形式)。 279 280**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 281 282**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 283 284**参数:** 285 286| 参数名 | 类型 | 必填 | 说明 | 287| ----- | --------- | ---- | ------------- | 288| agent | WantAgent | 是 | WantAgent对象。 | 289 290**返回值:** 291 292| 类型 | 说明 | 293| ----------------------------------------------------------- | ------------------------------------------------------------ | 294| Promise\<string\> | 以Promise形式返回获取WantAgent实例的包名。 | 295 296**错误码:** 297 298以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 299 300| 错误码ID | 错误信息 | 301|-----------|--------------------| 302| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 303| 16000007 | Service busy. There are concurrent tasks. Try again later. | 304| 16000151 | Invalid wantagent object.| 305 306**示例:** 307 308```ts 309import { wantAgent, Want } from '@kit.AbilityKit'; 310import type { WantAgent } from '@kit.AbilityKit'; 311import { BusinessError } from '@kit.BasicServicesKit'; 312 313//wantAgent对象 314let wantAgentData: WantAgent; 315//WantAgentInfo对象 316let wantAgentInfo: wantAgent.WantAgentInfo = { 317 wants: [ 318 { 319 deviceId: 'deviceId', 320 bundleName: 'com.example.myapplication', 321 abilityName: 'EntryAbility', 322 action: 'action1', 323 entities: ['entity1'], 324 type: 'MIMETYPE', 325 uri: 'key={true,true,false}', 326 parameters: 327 { 328 mykey0: 2222, 329 mykey1: [1, 2, 3], 330 mykey2: '[1, 2, 3]', 331 mykey3: 'ssssssssssssssssssssssssss', 332 mykey4: [false, true, false], 333 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 334 mykey6: true, 335 } 336 } as Want 337 ], 338 actionType: wantAgent.OperationType.START_ABILITY, 339 requestCode: 0, 340 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 341}; 342 343//getWantAgent回调 344function getWantAgentCallback(err: BusinessError, data: WantAgent) { 345 if (err) { 346 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 347 } else { 348 wantAgentData = data; 349 } 350 try { 351 wantAgent.getBundleName(wantAgentData).then((data)=>{ 352 console.info(`getBundleName ok! ${JSON.stringify(data)}`); 353 }).catch((err: BusinessError)=>{ 354 console.error(`getBundleName failed! ${err.code} ${err.message}`); 355 }); 356 } catch(err){ 357 console.error(`getBundleName failed! ${err.code} ${err.message}`); 358 } 359} 360try { 361 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 362} catch(err) { 363 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 364} 365``` 366 367## wantAgent.getUid 368 369getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void 370 371获取WantAgent实例的用户ID(callback形式)。 372 373**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 374 375**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 376 377**参数:** 378 379| 参数名 | 类型 | 必填 | 说明 | 380| -------- | ----------------------- | ---- | ----------------------------------- | 381| agent | WantAgent | 是 | WantAgent对象。 | 382| callback | AsyncCallback\<number\> | 是 | 获取WantAgent实例的用户ID的回调方法。 | 383 384**错误码:** 385 386以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 387 388| 错误码ID | 错误信息 | 389|-----------|--------------------| 390| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 391| 16000007 | Service busy. There are concurrent tasks. Try again later. | 392| 16000151 | Invalid wantagent object.| 393 394**示例:** 395 396```ts 397import { wantAgent, Want } from '@kit.AbilityKit'; 398import type { WantAgent } from '@kit.AbilityKit'; 399import { BusinessError } from '@kit.BasicServicesKit'; 400 401//wantAgent对象 402let wantAgentData: WantAgent; 403//WantAgentInfo对象 404let wantAgentInfo: wantAgent.WantAgentInfo = { 405 wants: [ 406 { 407 deviceId: 'deviceId', 408 bundleName: 'com.example.myapplication', 409 abilityName: 'EntryAbility', 410 action: 'action1', 411 entities: ['entity1'], 412 type: 'MIMETYPE', 413 uri: 'key={true,true,false}', 414 parameters: 415 { 416 mykey0: 2222, 417 mykey1: [1, 2, 3], 418 mykey2: '[1, 2, 3]', 419 mykey3: 'ssssssssssssssssssssssssss', 420 mykey4: [false, true, false], 421 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 422 mykey6: true, 423 } 424 } as Want 425 ], 426 actionType: wantAgent.OperationType.START_ABILITY, 427 requestCode: 0, 428 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 429}; 430 431//getWantAgent回调 432function getWantAgentCallback(err: BusinessError, data: WantAgent) { 433 if (err) { 434 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 435 } else { 436 wantAgentData = data; 437 } 438 //getUid回调 439 let getUidCallback = (err: BusinessError, data: number) => { 440 if (err) { 441 console.error(`getUid failed! ${err.code} ${err.message}`); 442 } else { 443 console.info(`getUid ok! ${JSON.stringify(data)}`); 444 } 445 } 446 try { 447 wantAgent.getUid(wantAgentData, getUidCallback); 448 } catch (err) { 449 console.error(`getUid failed! ${err.code} ${err.message}`); 450 } 451} 452 453try { 454 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 455} catch (err) { 456 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 457} 458``` 459 460## wantAgent.getUid 461 462getUid(agent: WantAgent): Promise\<number\> 463 464获取WantAgent实例的用户ID(Promise形式)。 465 466**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 467 468**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 469 470**参数:** 471 472| 参数名 | 类型 | 必填 | 说明 | 473| ----- | --------- | ---- | ------------- | 474| agent | WantAgent | 是 | WantAgent对象。 | 475 476**返回值:** 477 478| 类型 | 说明 | 479| ----------------------------------------------------------- | ------------------------------------------------------------ | 480| Promise\<number\> | 以Promise形式返回获取WantAgent实例的用户ID。 | 481 482**错误码:** 483 484以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 485 486| 错误码ID | 错误信息 | 487|-----------|--------------------| 488| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 489| 16000007 | Service busy. There are concurrent tasks. Try again later. | 490| 16000151 | Invalid wantagent object.| 491 492**示例:** 493 494```ts 495import { wantAgent, Want } from '@kit.AbilityKit'; 496import type { WantAgent } from '@kit.AbilityKit'; 497import { BusinessError } from '@kit.BasicServicesKit'; 498 499//wantAgent对象 500let wantAgentData: WantAgent; 501//WantAgentInfo对象 502let wantAgentInfo: wantAgent.WantAgentInfo = { 503 wants: [ 504 { 505 deviceId: 'deviceId', 506 bundleName: 'com.example.myapplication', 507 abilityName: 'EntryAbility', 508 action: 'action1', 509 entities: ['entity1'], 510 type: 'MIMETYPE', 511 uri: 'key={true,true,false}', 512 parameters: 513 { 514 mykey0: 2222, 515 mykey1: [1, 2, 3], 516 mykey2: '[1, 2, 3]', 517 mykey3: 'ssssssssssssssssssssssssss', 518 mykey4: [false, true, false], 519 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 520 mykey6: true, 521 } 522 } as Want 523 ], 524 actionType: wantAgent.OperationType.START_ABILITY, 525 requestCode: 0, 526 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 527}; 528 529//getWantAgent回调 530function getWantAgentCallback(err: BusinessError, data: WantAgent) { 531 if (err) { 532 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 533 } else { 534 wantAgentData = data; 535 } 536 try { 537 wantAgent.getUid(wantAgentData).then((data) => { 538 console.info(`getUid ok! ${JSON.stringify(data)}`); 539 }).catch((err: BusinessError) => { 540 console.error(`getUid failed! ${err.code} ${err.message}`); 541 }); 542 } catch (err) { 543 console.error(`getUid failed! ${err.code} ${err.message}`); 544 } 545} 546 547try { 548 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 549} catch (err) { 550 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 551} 552``` 553 554## wantAgent.cancel 555 556cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void 557 558取消WantAgent实例(callback形式)。 559 560**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 561 562**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 563 564**参数:** 565 566| 参数名 | 类型 | 必填 | 说明 | 567| -------- | --------------------- | ---- | --------------------------- | 568| agent | WantAgent | 是 | WantAgent对象。 | 569| callback | AsyncCallback\<void\> | 是 | 取消WantAgent实例的回调方法。 | 570 571**错误码:** 572 573以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 574 575| 错误码ID | 错误信息 | 576|-----------|--------------------| 577| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 578| 16000007 | Service busy. There are concurrent tasks. Try again later. | 579| 16000151 | Invalid wantagent object.| 580 581**示例:** 582 583```ts 584import { wantAgent, Want } from '@kit.AbilityKit'; 585import type { WantAgent } from '@kit.AbilityKit'; 586import { BusinessError } from '@kit.BasicServicesKit'; 587 588//wantAgent对象 589let wantAgentData: WantAgent; 590//WantAgentInfo对象 591let wantAgentInfo: wantAgent.WantAgentInfo = { 592 wants: [ 593 { 594 deviceId: 'deviceId', 595 bundleName: 'com.example.myapplication', 596 abilityName: 'EntryAbility', 597 action: 'action1', 598 entities: ['entity1'], 599 type: 'MIMETYPE', 600 uri: 'key={true,true,false}', 601 parameters: 602 { 603 mykey0: 2222, 604 mykey1: [1, 2, 3], 605 mykey2: '[1, 2, 3]', 606 mykey3: 'ssssssssssssssssssssssssss', 607 mykey4: [false, true, false], 608 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 609 mykey6: true, 610 } 611 } as Want 612 ], 613 actionType: wantAgent.OperationType.START_ABILITY, 614 requestCode: 0, 615 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 616}; 617 618//getWantAgent回调 619function getWantAgentCallback(err: BusinessError, data: WantAgent) { 620 if (err) { 621 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 622 } else { 623 wantAgentData = data; 624 } 625 //cancel回调 626 let cancelCallback = (err: BusinessError, data: void) => { 627 if (err) { 628 console.error(`cancel failed! ${err.code} ${err.message}`); 629 } else { 630 console.info(`cancel ok!`); 631 } 632 } 633 try { 634 wantAgent.cancel(wantAgentData, cancelCallback); 635 } catch (err) { 636 console.error(`cancel failed! ${err.code} ${err.message}`); 637 } 638} 639 640try { 641 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 642} catch (err) { 643 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 644} 645``` 646 647## wantAgent.cancel 648 649cancel(agent: WantAgent): Promise\<void\> 650 651取消WantAgent实例(Promise形式)。 652 653**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 654 655**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 656 657**参数:** 658 659| 参数名 | 类型 | 必填 | 说明 | 660| ----- | --------- | ---- | ------------- | 661| agent | WantAgent | 是 | WantAgent对象。 | 662 663**返回值:** 664 665| 类型 | 说明 | 666| --------------- | ------------------------------- | 667| Promise\<void\> | 以Promise形式获取异步返回结果。 | 668 669**错误码:** 670 671以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 672 673| 错误码ID | 错误信息 | 674|-----------|--------------------| 675| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 676| 16000007 | Service busy. There are concurrent tasks. Try again later. | 677| 16000151 | Invalid wantagent object.| 678 679**示例:** 680 681```ts 682import { wantAgent, Want } from '@kit.AbilityKit'; 683import type { WantAgent } from '@kit.AbilityKit'; 684import { BusinessError } from '@kit.BasicServicesKit'; 685 686//wantAgent对象 687let wantAgentData: WantAgent; 688//WantAgentInfo对象 689let wantAgentInfo: wantAgent.WantAgentInfo = { 690 wants: [ 691 { 692 deviceId: 'deviceId', 693 bundleName: 'com.example.myapplication', 694 abilityName: 'EntryAbility', 695 action: 'action1', 696 entities: ['entity1'], 697 type: 'MIMETYPE', 698 uri: 'key={true,true,false}', 699 parameters: 700 { 701 mykey0: 2222, 702 mykey1: [1, 2, 3], 703 mykey2: '[1, 2, 3]', 704 mykey3: 'ssssssssssssssssssssssssss', 705 mykey4: [false, true, false], 706 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 707 mykey6: true, 708 } 709 } as Want 710 ], 711 actionType: wantAgent.OperationType.START_ABILITY, 712 requestCode: 0, 713 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 714}; 715 716//getWantAgent回调 717function getWantAgentCallback(err: BusinessError, data: WantAgent) { 718 if (err) { 719 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 720 } else { 721 wantAgentData = data; 722 } 723 try { 724 wantAgent.cancel(wantAgentData).then((data) => { 725 console.info('cancel ok!'); 726 }).catch((err: BusinessError) => { 727 console.error(`cancel failed! ${err.code} ${err.message}`); 728 }); 729 } catch (err) { 730 console.error(`cancel failed! ${err.code} ${err.message}`); 731 } 732} 733 734try { 735 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 736} catch (err) { 737 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 738} 739``` 740 741## wantAgent.trigger 742 743trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<CompleteData\>): void 744 745主动激发WantAgent实例(callback形式)。 746 747**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 748 749**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 750 751**参数:** 752 753| 参数名 | 类型 | 必填 | 说明 | 754| ----------- | ----------------------------- | ---- | ------------------------------- | 755| agent | WantAgent | 是 | WantAgent对象。 | 756| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | 是 | TriggerInfo对象。 | 757| callback | AsyncCallback\<[CompleteData](#completedata)\> | 否 | 主动激发WantAgent实例的回调方法。 | 758 759**错误码:** 760 761以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 762 763| 错误码ID | 错误信息 | 764|-----------|--------------------| 765| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 766 767**示例:** 768 769```ts 770import { wantAgent, Want } from '@kit.AbilityKit'; 771import type { WantAgent } from '@kit.AbilityKit'; 772import { BusinessError } from '@kit.BasicServicesKit'; 773 774//wantAgent对象 775let wantAgentData: WantAgent; 776// triggerInfo 777let triggerInfo: wantAgent.TriggerInfo = { 778 code: 0 //自定义义结果码 779}; 780//WantAgentInfo对象 781let wantAgentInfo: wantAgent.WantAgentInfo = { 782 wants: [ 783 { 784 deviceId: 'deviceId', 785 bundleName: 'com.example.myapplication', 786 abilityName: 'EntryAbility', 787 action: 'action1', 788 entities: ['entity1'], 789 type: 'MIMETYPE', 790 uri: 'key={true,true,false}', 791 parameters: 792 { 793 mykey0: 2222, 794 mykey1: [1, 2, 3], 795 mykey2: '[1, 2, 3]', 796 mykey3: 'ssssssssssssssssssssssssss', 797 mykey4: [false, true, false], 798 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 799 mykey6: true, 800 } 801 } as Want 802 ], 803 actionType: wantAgent.OperationType.START_ABILITY, 804 requestCode: 0, 805 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 806}; 807 808//getWantAgent回调 809function getWantAgentCallback(err: BusinessError, data: WantAgent) { 810 if (err) { 811 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 812 } else { 813 wantAgentData = data; 814 } 815 //trigger回调 816 let triggerCallback = (err: BusinessError, data: wantAgent.CompleteData) => { 817 if (err) { 818 console.error(`getUid failed! ${err.code} ${err.message}`); 819 } else { 820 console.info(`getUid ok! ${JSON.stringify(data)}`); 821 } 822 } 823 try { 824 wantAgent.trigger(wantAgentData, triggerInfo, triggerCallback); 825 } catch (err) { 826 console.error(`getUid failed! ${err.code} ${err.message}`); 827 } 828} 829 830try { 831 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 832} catch (err) { 833 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 834} 835``` 836 837## wantAgent.equal 838 839equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void 840 841判断两个WantAgent实例是否相等(Callback形式),以此来判断是否是来自同一应用的相同操作。 842 843**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 844 845**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 846 847**参数:** 848 849| 参数名 | 类型 | 必填 | 说明 | 850| ---------- | ------------------------ | ---- | --------------------------------------- | 851| agent | WantAgent | 是 | WantAgent对象。 | 852| otherAgent | WantAgent | 是 | WantAgent对象。 | 853| callback | AsyncCallback\<boolean\> | 是 | 判断两个WantAgent实例是否相等的回调方法。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等。 | 854 855**错误码:** 856 857以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 858 859| 错误码ID | 错误信息 | 860|-----------|--------------------| 861| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 862 863**示例:** 864 865```ts 866import { wantAgent, Want } from '@kit.AbilityKit'; 867import type { WantAgent } from '@kit.AbilityKit'; 868import { BusinessError } from '@kit.BasicServicesKit'; 869 870//wantAgent对象 871let wantAgent1: WantAgent; 872let wantAgent2: WantAgent; 873//WantAgentInfo对象 874let wantAgentInfo: wantAgent.WantAgentInfo = { 875 wants: [ 876 { 877 deviceId: 'deviceId', 878 bundleName: 'com.example.myapplication', 879 abilityName: 'EntryAbility', 880 action: 'action1', 881 entities: ['entity1'], 882 type: 'MIMETYPE', 883 uri: 'key={true,true,false}', 884 parameters: 885 { 886 mykey0: 2222, 887 mykey1: [1, 2, 3], 888 mykey2: '[1, 2, 3]', 889 mykey3: 'ssssssssssssssssssssssssss', 890 mykey4: [false, true, false], 891 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 892 mykey6: true, 893 } 894 } as Want 895 ], 896 actionType: wantAgent.OperationType.START_ABILITY, 897 requestCode: 0, 898 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 899}; 900 901//getWantAgent回调 902function getWantAgentCallback(err: BusinessError, data: WantAgent) { 903 if (err) { 904 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 905 } else { 906 wantAgent1 = data; 907 wantAgent2 = data; 908 } 909 //equal回调 910 let equalCallback = (err: BusinessError, data: boolean) => { 911 if (err) { 912 console.error(`equal failed! ${err.code} ${err.message}`); 913 } else { 914 console.info(`equal ok! ${JSON.stringify(data)}`); 915 } 916 } 917 try { 918 wantAgent.equal(wantAgent1, wantAgent2, equalCallback); 919 } catch (err) { 920 console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 921 } 922} 923 924try { 925 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 926} catch (err) { 927 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 928} 929``` 930 931## wantAgent.equal 932 933equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\> 934 935判断两个WantAgent实例是否相等(Promise形式),以此来判断是否是来自同一应用的相同操作。 936 937**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 938 939**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 940 941**参数:** 942 943| 参数名 | 类型 | 必填 | 说明 | 944| ---------- | --------- | ---- | ------------- | 945| agent | WantAgent | 是 | WantAgent对象。 | 946| otherAgent | WantAgent | 是 | WantAgent对象。 | 947 948**返回值:** 949 950| 类型 | 说明 | 951| ----------------------------------------------------------- | ------------------------------------------------------------ | 952| Promise\<boolean\> | 以Promise形式返回获取判断两个WantAgent实例是否相等的结果。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等。 | 953 954**错误码:** 955 956以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 957 958| 错误码ID | 错误信息 | 959|-----------|--------------------| 960| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 961 962**示例:** 963 964```ts 965import { wantAgent, Want } from '@kit.AbilityKit'; 966import type { WantAgent } from '@kit.AbilityKit'; 967import { BusinessError } from '@kit.BasicServicesKit'; 968 969//wantAgent对象 970let wantAgent1: WantAgent; 971let wantAgent2: WantAgent; 972//WantAgentInfo对象 973let wantAgentInfo: wantAgent.WantAgentInfo = { 974 wants: [ 975 { 976 deviceId: 'deviceId', 977 bundleName: 'com.example.myapplication', 978 abilityName: 'EntryAbility', 979 action: 'action1', 980 entities: ['entity1'], 981 type: 'MIMETYPE', 982 uri: 'key={true,true,false}', 983 parameters: 984 { 985 mykey0: 2222, 986 mykey1: [1, 2, 3], 987 mykey2: '[1, 2, 3]', 988 mykey3: 'ssssssssssssssssssssssssss', 989 mykey4: [false, true, false], 990 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 991 mykey6: true, 992 } 993 } as Want 994 ], 995 actionType: wantAgent.OperationType.START_ABILITY, 996 requestCode: 0, 997 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 998}; 999 1000//getWantAgent回调 1001function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1002 if (err) { 1003 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1004 } else { 1005 wantAgent1 = data; 1006 wantAgent2 = data; 1007 } 1008 try { 1009 wantAgent.equal(wantAgent1, wantAgent2).then((data) => { 1010 console.info(`equal ok! ${JSON.stringify(data)}`); 1011 }).catch((err: BusinessError) => { 1012 console.error(`equal failed! ${err.code} ${err.message}`); 1013 }) 1014 } catch (err) { 1015 console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1016 } 1017} 1018 1019try { 1020 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1021} catch (err) { 1022 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1023} 1024``` 1025 1026## wantAgent.getOperationType 1027 1028getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void 1029 1030获取一个WantAgent的OperationType信息(callback形式)。 1031 1032**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1033 1034**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1035 1036**参数:** 1037 1038| 参数名 | 类型 | 必填 | 说明 | 1039| ---------- | ------------------------ | ---- | --------------------------------------- | 1040| agent | WantAgent | 是 | WantAgent对象。 | 1041| callback | AsyncCallback\<number> | 是 | 获取一个WantAgent的OperationType信息的回调方法。 | 1042 1043**错误码:** 1044 1045以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 1046 1047| 错误码ID | 错误信息 | 1048|-----------|--------------------| 1049| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1050| 16000007 | Service busy. There are concurrent tasks. Try again later. | 1051| 16000015 | Service timeout.| 1052| 16000151 | Invalid wantagent object.| 1053 1054**示例:** 1055 1056```ts 1057import { wantAgent, Want } from '@kit.AbilityKit'; 1058import type { WantAgent } from '@kit.AbilityKit'; 1059import { BusinessError } from '@kit.BasicServicesKit'; 1060 1061//wantAgent对象 1062let wantAgentData: WantAgent; 1063//WantAgentInfo对象 1064let wantAgentInfo: wantAgent.WantAgentInfo = { 1065 wants: [ 1066 { 1067 deviceId: 'deviceId', 1068 bundleName: 'com.example.myapplication', 1069 abilityName: 'EntryAbility', 1070 action: 'action1', 1071 entities: ['entity1'], 1072 type: 'MIMETYPE', 1073 uri: 'key={true,true,false}', 1074 parameters: 1075 { 1076 mykey0: 2222, 1077 mykey1: [1, 2, 3], 1078 mykey2: '[1, 2, 3]', 1079 mykey3: 'ssssssssssssssssssssssssss', 1080 mykey4: [false, true, false], 1081 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 1082 mykey6: true, 1083 } 1084 } as Want 1085 ], 1086 actionType: wantAgent.OperationType.START_ABILITY, 1087 requestCode: 0, 1088 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1089}; 1090 1091//getWantAgent回调 1092function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1093 if (err) { 1094 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1095 } else { 1096 wantAgentData = data; 1097 } 1098 //getOperationTypeCallback回调 1099 let getOperationTypeCallback = (err: BusinessError, data: number) => { 1100 if (err) { 1101 console.error(`getOperationType failed! ${err.code} ${err.message}`); 1102 } else { 1103 console.info(`getOperationType ok! ${JSON.stringify(data)}`); 1104 } 1105 } 1106 try { 1107 wantAgent.getOperationType(wantAgentData, getOperationTypeCallback); 1108 } catch (err) { 1109 console.error(`getOperationTypeCallback failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1110 } 1111} 1112 1113try { 1114 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1115} catch (err) { 1116 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1117} 1118``` 1119 1120## wantAgent.getOperationType 1121 1122getOperationType(agent: WantAgent): Promise\<number> 1123 1124获取一个WantAgent的OperationType信息(Promise形式)。 1125 1126**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1127 1128**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1129 1130**参数:** 1131 1132| 参数名 | 类型 | 必填 | 说明 | 1133| ---------- | --------- | ---- | ------------- | 1134| agent | WantAgent | 是 | WantAgent对象。 | 1135 1136**返回值:** 1137 1138| 类型 | 说明 | 1139| ----------------------------------------------------------- | ------------------------------------------------------------ | 1140| Promise\<number> | 以Promise形式返回获取operationType的结果。 | 1141 1142**错误码:** 1143 1144以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 1145 1146| 错误码ID | 错误信息 | 1147|-----------|--------------------| 1148| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1149| 16000007 | Service busy. There are concurrent tasks. Try again later. | 1150| 16000015 | Service timeout.| 1151| 16000151 | Invalid wantagent object.| 1152 1153错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md) 1154 1155**示例:** 1156 1157```ts 1158import { wantAgent, Want } from '@kit.AbilityKit'; 1159import type { WantAgent } from '@kit.AbilityKit'; 1160import { BusinessError } from '@kit.BasicServicesKit'; 1161 1162//wantAgent对象 1163let wantAgentData: WantAgent; 1164//WantAgentInfo对象 1165let wantAgentInfo: wantAgent.WantAgentInfo = { 1166 wants: [ 1167 { 1168 deviceId: 'deviceId', 1169 bundleName: 'com.example.myapplication', 1170 abilityName: 'EntryAbility', 1171 action: 'action1', 1172 entities: ['entity1'], 1173 type: 'MIMETYPE', 1174 uri: 'key={true,true,false}', 1175 parameters: 1176 { 1177 mykey0: 2222, 1178 mykey1: [1, 2, 3], 1179 mykey2: '[1, 2, 3]', 1180 mykey3: 'ssssssssssssssssssssssssss', 1181 mykey4: [false, true, false], 1182 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 1183 mykey6: true, 1184 } 1185 } as Want 1186 ], 1187 actionType: wantAgent.OperationType.START_ABILITY, 1188 requestCode: 0, 1189 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1190}; 1191 1192//getWantAgent回调 1193function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1194 if (err) { 1195 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1196 } else { 1197 wantAgentData = data; 1198 } 1199 try { 1200 wantAgent.getOperationType(wantAgentData).then((data) => { 1201 console.info(`getOperationType ok! ${JSON.stringify(data)}`); 1202 }).catch((err: BusinessError) => { 1203 console.error(`getOperationType failed! ${err.code} ${err.message}`); 1204 }); 1205 } catch (err) { 1206 console.error(`getOperationType failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1207 } 1208} 1209 1210try { 1211 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1212} catch (err) { 1213 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1214} 1215``` 1216 1217## WantAgentFlags 1218 1219表示使用WantAgent类型的枚举。 1220 1221**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1222 1223**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1224 1225| 名称 | 值 | 说明 | 1226| ------------------- | -------------- |-------------------------------------------------------------------------| 1227| ONE_TIME_FLAG | 0 | WantAgent仅能使用一次。 | 1228| NO_BUILD_FLAG | 1 | 如果描述WantAgent对象不存在,则不创建它,直接返回null。 | 1229| CANCEL_PRESENT_FLAG | 2 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。 | 1230| UPDATE_PRESENT_FLAG | 3 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。 | 1231| CONSTANT_FLAG | 4 | WantAgent是不可变的。 | 1232| REPLACE_ELEMENT | 5 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代。当前版本暂不支持。 | 1233| REPLACE_ACTION | 6 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代。当前版本暂不支持。 | 1234| REPLACE_URI | 7 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代。当前版本暂不支持。 | 1235| REPLACE_ENTITIES | 8 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代。当前版本暂不支持。 | 1236| REPLACE_BUNDLE | 9 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代。当前版本暂不支持。 | 1237 1238 1239 1240## OperationType 1241 1242表示操作WantAgent类型的枚举。 1243 1244**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1245 1246**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1247 1248| 名称 | 值 | 说明 | 1249| ----------------- | ------------- | ------------------------- | 1250| UNKNOWN_TYPE | 0 | 不识别的类型。 | 1251| START_ABILITY | 1 | 开启一个有页面的Ability。 | 1252| START_ABILITIES | 2 | 开启多个有页面的Ability。 | 1253| START_SERVICE | 3 | 开启一个无页面的Ability(仅在FA模型下生效)。 | 1254| SEND_COMMON_EVENT | 4 | 发送一个公共事件。 | 1255 1256 1257 1258## CompleteData 1259 1260表示主动激发WantAgent返回的数据。 1261 1262**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1263 1264**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1265 1266| 名称 | 类型 | 只读 | 可选 | 说明 | 1267| -------- | -------- | -------- | -------- | -------- | 1268| info | WantAgent | 否 | 否 | 触发的wantAgent。 | 1269| want | [Want](js-apis-app-ability-want.md#属性) | 否 | 否 | 存在的被触发的want。 | 1270| finalCode | number | 否 | 否 | 触发wantAgent的请求代码。 | 1271| finalData | string | 否 | 否 | 公共事件收集的最终数据。 | 1272| extraInfo | Record\<string, Object> | 否 |是 | 额外数据。 | 1273 1274## TriggerInfo 1275 1276type TriggerInfo = _TriggerInfo 1277 1278TriggerInfo对象。 1279 1280**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1281 1282**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1283 1284| 类型 | 说明 | 1285| --- | --- | 1286| [_TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | TriggerInfo对象。 | 1287 1288## WantAgentInfo 1289 1290type WantAgentInfo = _WantAgentInfo 1291 1292WantAgentInfo对象。 1293 1294**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1295 1296**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1297 1298| 类型 | 说明 | 1299| --- | --- | 1300| [_WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | WantAgentInfo对象。 | 1301 1302