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