1# @ohos.wantAgent (WantAgent模块) 2 3WantAgent模块提供了创建WantAgent实例、获取实例的用户ID、获取want信息、比较WantAgent实例和获取bundle名称等能力。 4 5> **说明:** 6> 7> 本模块首批接口从API version 7开始支持,从API version 9废弃,替换模块为[@ohos.app.ability.wantAgent](js-apis-app-ability-wantAgent.md)。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 10 11```ts 12import WantAgent from '@ohos.wantAgent'; 13``` 14 15## WantAgent.getWant 16 17getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void 18 19获取WantAgent中的Want(callback形式)。 20 21**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 22 23**系统API**:该接口为系统接口,三方应用不支持调用。 24 25**参数:** 26 27| 参数名 | 类型 | 必填 | 说明 | 28| -------- | -------------------------- | ---- | ----------------------- | 29| agent | [WantAgent](js-apis-wantAgent.md) | 是 | WantAgent信息。 | 30| callback | AsyncCallback\<Want\> | 是 | 获取WantAgent中的Want的回调方法。 | 31 32**示例:** 33 34```ts 35import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 36import Want from '@ohos.app.ability.Want'; 37import { BusinessError } from '@ohos.base'; 38 39//wantAgent对象 40let wantAgent: _WantAgent; 41 42//getWantAgent回调 43function getWantAgentCallback(err: BusinessError, data: _WantAgent) { 44 console.info('==========================>getWantAgentCallback=======================>'); 45 if (err.code == 0) { 46 wantAgent = data; 47 } else { 48 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 49 return; 50 } 51 52 //getWant回调 53 let getWantCallback = (err: BusinessError, data: Want) => { 54 console.info('==========================>getWantCallback=======================>'); 55 } 56 WantAgent.getWant(wantAgent, getWantCallback); 57} 58 59WantAgent.getWantAgent({ 60 wants: [ 61 { 62 deviceId: 'deviceId', 63 bundleName: 'com.neu.setResultOnAbilityResultTest1', 64 abilityName: 'com.example.test.EntryAbility', 65 action: 'action1', 66 entities: ['entity1'], 67 type: 'MIMETYPE', 68 uri: 'key={true,true,false}', 69 parameters: 70 { 71 mykey0: 2222, 72 mykey1: [1, 2, 3], 73 mykey2: '[1, 2, 3]', 74 mykey3: 'ssssssssssssssssssssssssss', 75 mykey4: [false, true, false], 76 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 77 mykey6: true, 78 } 79 } 80 ], 81 operationType: WantAgent.OperationType.START_ABILITIES, 82 requestCode: 0, 83 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 84}, getWantAgentCallback); 85``` 86 87## WantAgent.getWant 88 89getWant(agent: WantAgent): Promise\<Want\> 90 91获取WantAgent中的Want(Promise形式)。 92 93**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 94 95**系统API**:该接口为系统接口,三方应用不支持调用。 96 97**参数:** 98 99| 参数名 | 类型 | 必填 | 说明 | 100| ---- | ------------- | ---- | ------------- | 101| agent | [WantAgent](js-apis-wantAgent.md) | 是 | WantAgent信息。 | 102 103**返回值:** 104 105| 类型 | 说明 | 106| ----------------------------------------------------------- | ------------------------------------------------------------ | 107| Promise\<Want\> | 以Promise形式返回Want。 | 108 109**示例:** 110 111```ts 112import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 113import { BusinessError } from '@ohos.base'; 114 115//wantAgent对象 116let wantAgent: _WantAgent; 117 118WantAgent.getWantAgent({ 119 wants: [ 120 { 121 deviceId: 'deviceId', 122 bundleName: 'com.neu.setResultOnAbilityResultTest1', 123 abilityName: 'com.example.test.EntryAbility', 124 action: 'action1', 125 entities: ['entity1'], 126 type: 'MIMETYPE', 127 uri: 'key={true,true,false}', 128 parameters: 129 { 130 mykey0: 2222, 131 mykey1: [1, 2, 3], 132 mykey2: '[1, 2, 3]', 133 mykey3: 'ssssssssssssssssssssssssss', 134 mykey4: [false, true, false], 135 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 136 mykey6: true, 137 } 138 } 139 ], 140 operationType: WantAgent.OperationType.START_ABILITIES, 141 requestCode: 0, 142 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 143}).then((data) => { 144 console.info('==========================>getWantAgentCallback=======================>'); 145 wantAgent = data; 146 if (wantAgent) { 147 WantAgent.getWant(wantAgent).then((data) => { 148 console.info('==========================>getWantCallback=======================>'); 149 }); 150 } 151}); 152``` 153 154## WantAgent.getWantAgent 155 156getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void 157 158创建WantAgent(callback形式)。 创建失败返回的WantAgent为空值。 159 160**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 161 162**参数:** 163 164| 参数名 | 类型 | 必填 | 说明 | 165| -------- | -------------------------- | ---- | ----------------------- | 166| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是 | WantAgent信息。 | 167| callback | AsyncCallback\<WantAgent\> | 是 | 创建WantAgent的回调方法。 | 168 169**示例:** 170 171```ts 172import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 173import { BusinessError } from '@ohos.base'; 174 175//getWantAgent回调 176function getWantAgentCallback(err: BusinessError, data: _WantAgent) { 177 if (err.code) { 178 console.info('getWantAgent Callback err:' + JSON.stringify(err)) 179 } else { 180 console.info('getWantAgent Callback success') 181 } 182} 183 184WantAgent.getWantAgent({ 185 wants: [ 186 { 187 deviceId: 'deviceId', 188 bundleName: 'com.neu.setResultOnAbilityResultTest1', 189 abilityName: 'com.example.test.EntryAbility', 190 action: 'action1', 191 entities: ['entity1'], 192 type: 'MIMETYPE', 193 uri: 'key={true,true,false}', 194 parameters: 195 { 196 mykey0: 2222, 197 mykey1: [1, 2, 3], 198 mykey2: '[1, 2, 3]', 199 mykey3: 'ssssssssssssssssssssssssss', 200 mykey4: [false, true, false], 201 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 202 mykey6: true, 203 } 204 } 205 ], 206 operationType: WantAgent.OperationType.START_ABILITIES, 207 requestCode: 0, 208 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 209}, getWantAgentCallback); 210``` 211 212## WantAgent.getWantAgent 213 214getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> 215 216创建WantAgent(Promise形式)。 创建失败返回的WantAgent为空值。 217 218**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 219 220**参数:** 221 222| 参数名 | 类型 | 必填 | 说明 | 223| ---- | ------------- | ---- | ------------- | 224| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是 | WantAgent信息。 | 225 226**返回值:** 227 228| 类型 | 说明 | 229| ----------------------------------------------------------- | ------------------------------------------------------------ | 230| Promise\<WantAgent\> | 以Promise形式返回WantAgent。 | 231 232**示例:** 233 234```ts 235import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 236 237WantAgent.getWantAgent({ 238 wants: [ 239 { 240 deviceId: 'deviceId', 241 bundleName: 'com.neu.setResultOnAbilityResultTest1', 242 abilityName: 'com.example.test.EntryAbility', 243 action: 'action1', 244 entities: ['entity1'], 245 type: 'MIMETYPE', 246 uri: 'key={true,true,false}', 247 parameters: 248 { 249 mykey0: 2222, 250 mykey1: [1, 2, 3], 251 mykey2: '[1, 2, 3]', 252 mykey3: 'ssssssssssssssssssssssssss', 253 mykey4: [false, true, false], 254 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 255 mykey6: true, 256 } 257 } 258 ], 259 operationType: WantAgent.OperationType.START_ABILITIES, 260 requestCode: 0, 261 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 262}).then((data: _WantAgent) => { 263 console.info('==========================>getWantAgentCallback=======================>'); 264}); 265``` 266 267## WantAgent.getBundleName 268 269getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void 270 271获取WantAgent实例的Bundle名称(callback形式)。 272 273**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 274 275**参数:** 276 277| 参数名 | 类型 | 必填 | 说明 | 278| -------- | ----------------------- | ---- | --------------------------------- | 279| agent | WantAgent | 是 | WantAgent对象。 | 280| callback | AsyncCallback\<string\> | 是 | 获取WantAgent实例的包名的回调方法。 | 281 282**示例:** 283 284```ts 285import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 286import { BusinessError } from '@ohos.base'; 287 288//wantAgent对象 289let wantAgent: _WantAgent; 290 291//getWantAgent回调 292function getWantAgentCallback(err: BusinessError, data: _WantAgent) { 293 console.info('==========================>getWantAgentCallback=======================>'); 294 if (err.code == 0) { 295 wantAgent = data; 296 } else { 297 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 298 return; 299 } 300 301 //getBundleName回调 302 let getBundleNameCallback = (err: BusinessError, data: string) => { 303 console.info('==========================>getBundleNameCallback=======================>'); 304 } 305 WantAgent.getBundleName(wantAgent, getBundleNameCallback); 306} 307 308WantAgent.getWantAgent({ 309 wants: [ 310 { 311 deviceId: 'deviceId', 312 bundleName: 'com.neu.setResultOnAbilityResultTest1', 313 abilityName: 'com.example.test.EntryAbility', 314 action: 'action1', 315 entities: ['entity1'], 316 type: 'MIMETYPE', 317 uri: 'key={true,true,false}', 318 parameters: 319 { 320 mykey0: 2222, 321 mykey1: [1, 2, 3], 322 mykey2: '[1, 2, 3]', 323 mykey3: 'ssssssssssssssssssssssssss', 324 mykey4: [false, true, false], 325 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 326 mykey6: true, 327 } 328 } 329 ], 330 operationType: WantAgent.OperationType.START_ABILITIES, 331 requestCode: 0, 332 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 333}, getWantAgentCallback) 334``` 335 336 337 338## WantAgent.getBundleName 339 340getBundleName(agent: WantAgent): Promise\<string\> 341 342获取WantAgent实例的Bundle名称(Promise形式)。 343 344**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 345 346**参数:** 347 348| 参数名 | 类型 | 必填 | 说明 | 349| ----- | --------- | ---- | ------------- | 350| agent | WantAgent | 是 | WantAgent对象。 | 351 352**返回值:** 353 354| 类型 | 说明 | 355| ----------------- | ------------------------------------------------ | 356| Promise\<string\> | 以Promise形式返回获取WantAgent实例的Bundle名称。 | 357 358**示例:** 359 360```ts 361import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 362 363//wantAgent对象 364let wantAgent: _WantAgent; 365 366WantAgent.getWantAgent({ 367 wants: [ 368 { 369 deviceId: 'deviceId', 370 bundleName: 'com.neu.setResultOnAbilityResultTest1', 371 abilityName: 'com.example.test.EntryAbility', 372 action: 'action1', 373 entities: ['entity1'], 374 type: 'MIMETYPE', 375 uri: 'key={true,true,false}', 376 parameters: 377 { 378 mykey0: 2222, 379 mykey1: [1, 2, 3], 380 mykey2: '[1, 2, 3]', 381 mykey3: 'ssssssssssssssssssssssssss', 382 mykey4: [false, true, false], 383 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 384 mykey6: true, 385 } 386 } 387 ], 388 operationType: WantAgent.OperationType.START_ABILITIES, 389 requestCode: 0, 390 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 391}).then((data: _WantAgent) => { 392 console.info('==========================>getWantAgentCallback=======================>'); 393 wantAgent = data; 394 if (wantAgent) { 395 WantAgent.getBundleName(wantAgent).then((data) => { 396 console.info('==========================>getBundleNameCallback=======================>'); 397 }); 398 } 399}); 400``` 401 402 403 404## WantAgent.getUid 405 406getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void 407 408获取WantAgent实例的用户ID(callback形式)。 409 410**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 411 412**参数:** 413 414| 参数名 | 类型 | 必填 | 说明 | 415| -------- | ----------------------- | ---- | ----------------------------------- | 416| agent | WantAgent | 是 | WantAgent对象。 | 417| callback | AsyncCallback\<number\> | 是 | 获取WantAgent实例的用户ID的回调方法。 | 418 419**示例:** 420 421```ts 422import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 423import { BusinessError } from '@ohos.base'; 424 425//wantAgent对象 426let wantAgent: _WantAgent; 427 428//getWantAgent回调 429function getWantAgentCallback(err: BusinessError, data: _WantAgent) { 430 console.info('==========================>getWantAgentCallback=======================>'); 431 if (err.code == 0) { 432 wantAgent = data; 433 } else { 434 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 435 return; 436 } 437 438 //getUid回调 439 let getUidCallback = (err: BusinessError, data: number) => { 440 console.info('==========================>getUidCallback=======================>'); 441 } 442 WantAgent.getUid(wantAgent, getUidCallback); 443} 444 445WantAgent.getWantAgent({ 446 wants: [ 447 { 448 deviceId: 'deviceId', 449 bundleName: 'com.neu.setResultOnAbilityResultTest1', 450 abilityName: 'com.example.test.EntryAbility', 451 action: 'action1', 452 entities: ['entity1'], 453 type: 'MIMETYPE', 454 uri: 'key={true,true,false}', 455 parameters: 456 { 457 mykey0: 2222, 458 mykey1: [1, 2, 3], 459 mykey2: '[1, 2, 3]', 460 mykey3: 'ssssssssssssssssssssssssss', 461 mykey4: [false, true, false], 462 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 463 mykey6: true, 464 } 465 } 466 ], 467 operationType: WantAgent.OperationType.START_ABILITIES, 468 requestCode: 0, 469 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 470}, getWantAgentCallback) 471``` 472 473 474 475## WantAgent.getUid 476 477getUid(agent: WantAgent): Promise\<number\> 478 479获取WantAgent实例的用户ID(Promise形式)。 480 481**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 482 483**参数:** 484 485| 参数名 | 类型 | 必填 | 说明 | 486| ----- | --------- | ---- | ------------- | 487| agent | WantAgent | 是 | WantAgent对象。 | 488 489**返回值:** 490 491| 类型 | 说明 | 492| ----------------------------------------------------------- | ------------------------------------------------------------ | 493| Promise\<number\> | 以Promise形式返回获取WantAgent实例的用户ID。 | 494 495**示例:** 496 497```ts 498import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 499 500//wantAgent对象 501let wantAgent: _WantAgent; 502 503WantAgent.getWantAgent({ 504 wants: [ 505 { 506 deviceId: 'deviceId', 507 bundleName: 'com.neu.setResultOnAbilityResultTest1', 508 abilityName: 'com.example.test.EntryAbility', 509 action: 'action1', 510 entities: ['entity1'], 511 type: 'MIMETYPE', 512 uri: 'key={true,true,false}', 513 parameters: 514 { 515 mykey0: 2222, 516 mykey1: [1, 2, 3], 517 mykey2: '[1, 2, 3]', 518 mykey3: 'ssssssssssssssssssssssssss', 519 mykey4: [false, true, false], 520 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 521 mykey6: true, 522 } 523 } 524 ], 525 operationType: WantAgent.OperationType.START_ABILITIES, 526 requestCode: 0, 527 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 528}).then((data) => { 529 console.info('==========================>getWantAgentCallback=======================>'); 530 wantAgent = data; 531 if (wantAgent) { 532 WantAgent.getUid(wantAgent).then((data) => { 533 console.info('==========================>getUidCallback=======================>'); 534 }); 535 } 536}); 537``` 538 539 540## WantAgent.cancel 541 542cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void 543 544取消WantAgent实例(callback形式)。 545 546**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 547 548**参数:** 549 550| 参数名 | 类型 | 必填 | 说明 | 551| -------- | --------------------- | ---- | --------------------------- | 552| agent | WantAgent | 是 | WantAgent对象。 | 553| callback | AsyncCallback\<void\> | 是 | 取消WantAgent实例的回调方法。 | 554 555**示例:** 556 557```ts 558import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 559import { BusinessError } from '@ohos.base'; 560 561//wantAgent对象 562let wantAgent: _WantAgent; 563 564//getWantAgent回调 565function getWantAgentCallback(err: BusinessError, data: _WantAgent) { 566 console.info('==========================>getWantAgentCallback=======================>'); 567 if (err.code == 0) { 568 wantAgent = data; 569 } else { 570 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 571 return; 572 } 573 574 //cancel回调 575 let cancelCallback = (err: BusinessError) => { 576 console.info('==========================>cancelCallback=======================>'); 577 } 578 WantAgent.cancel(wantAgent, cancelCallback); 579} 580 581WantAgent.getWantAgent({ 582 wants: [ 583 { 584 deviceId: 'deviceId', 585 bundleName: 'com.neu.setResultOnAbilityResultTest1', 586 abilityName: 'com.example.test.EntryAbility', 587 action: 'action1', 588 entities: ['entity1'], 589 type: 'MIMETYPE', 590 uri: 'key={true,true,false}', 591 parameters: 592 { 593 mykey0: 2222, 594 mykey1: [1, 2, 3], 595 mykey2: '[1, 2, 3]', 596 mykey3: 'ssssssssssssssssssssssssss', 597 mykey4: [false, true, false], 598 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 599 mykey6: true, 600 } 601 } 602 ], 603 operationType: WantAgent.OperationType.START_ABILITIES, 604 requestCode: 0, 605 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 606}, getWantAgentCallback) 607``` 608 609 610 611## WantAgent.cancel 612 613cancel(agent: WantAgent): Promise\<void\> 614 615取消WantAgent实例(Promise形式)。 616 617**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 618 619**参数:** 620 621| 参数名 | 类型 | 必填 | 说明 | 622| ----- | --------- | ---- | ------------- | 623| agent | WantAgent | 是 | WantAgent对象。 | 624 625**返回值:** 626 627| 类型 | 说明 | 628| --------------- | ------------------------------- | 629| Promise\<void\> | 以Promise形式获取异步返回结果。 | 630 631**示例:** 632 633```ts 634import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 635import { BusinessError } from '@ohos.base'; 636 637//wantAgent对象 638let wantAgent: _WantAgent; 639 640WantAgent.getWantAgent({ 641 wants: [ 642 { 643 deviceId: 'deviceId', 644 bundleName: 'com.neu.setResultOnAbilityResultTest1', 645 abilityName: 'com.example.test.EntryAbility', 646 action: 'action1', 647 entities: ['entity1'], 648 type: 'MIMETYPE', 649 uri: 'key={true,true,false}', 650 parameters: 651 { 652 mykey0: 2222, 653 mykey1: [1, 2, 3], 654 mykey2: '[1, 2, 3]', 655 mykey3: 'ssssssssssssssssssssssssss', 656 mykey4: [false, true, false], 657 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 658 mykey6: true, 659 } 660 } 661], 662 operationType: WantAgent.OperationType.START_ABILITIES, 663 requestCode: 0, 664 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 665}).then((data) => { 666 console.info('==========================>getWantAgentCallback=======================>'); 667 wantAgent = data; 668 if (wantAgent) { 669 WantAgent.cancel(wantAgent).then((data) => { 670 console.info('==========================>cancelCallback=======================>'); 671 }); 672 } 673}); 674``` 675 676 677 678## WantAgent.trigger 679 680trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>): void 681 682主动激发WantAgent实例(callback形式)。 683 684**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 685 686**参数:** 687 688| 参数名 | 类型 | 必填 | 说明 | 689| ----------- | ----------------------------- | ---- | ------------------------------- | 690| agent | WantAgent | 是 | WantAgent对象。 | 691| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | 是 | TriggerInfo对象。 | 692| callback | AsyncCallback\<CompleteData\> | 否 | 主动激发WantAgent实例的回调方法。 | 693 694**示例:** 695 696```ts 697import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 698import { BusinessError } from '@ohos.base'; 699 700//wantAgent对象 701let wantAgent: _WantAgent; 702 703//getWantAgent回调 704function getWantAgentCallback(err: BusinessError, data: _WantAgent) { 705 console.info('==========================>getWantAgentCallback=======================>'); 706 if (err.code == 0) { 707 wantAgent = data; 708 } else { 709 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 710 return; 711 } 712 713 //trigger回调 714 let triggerCallback = (data: WantAgent.CompleteData) => { 715 console.info('==========================>triggerCallback=======================>'); 716 } 717 718 WantAgent.trigger(wantAgent, {code:0}, triggerCallback) 719} 720 721WantAgent.getWantAgent({ 722 wants: [ 723 { 724 deviceId: 'deviceId', 725 bundleName: 'com.neu.setResultOnAbilityResultTest1', 726 abilityName: 'com.example.test.EntryAbility', 727 action: 'action1', 728 entities: ['entity1'], 729 type: 'MIMETYPE', 730 uri: 'key={true,true,false}', 731 parameters: 732 { 733 mykey0: 2222, 734 mykey1: [1, 2, 3], 735 mykey2: '[1, 2, 3]', 736 mykey3: 'ssssssssssssssssssssssssss', 737 mykey4: [false, true, false], 738 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 739 mykey6: true, 740 } 741 } 742 ], 743 operationType: WantAgent.OperationType.START_ABILITIES, 744 requestCode: 0, 745 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 746}, getWantAgentCallback) 747``` 748 749 750 751## WantAgent.equal 752 753equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void 754 755判断两个WantAgent实例是否相等(callback形式),以此来判断是否是来自同一应用的相同操作。 756 757**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 758 759**参数:** 760 761| 参数名 | 类型 | 必填 | 说明 | 762| ---------- | ------------------------ | ---- | --------------------------------------- | 763| agent | WantAgent | 是 | WantAgent对象。 | 764| otherAgent | WantAgent | 是 | WantAgent对象。 | 765| callback | AsyncCallback\<boolean\> | 是 | 判断两个WantAgent实例是否相等的回调方法。 | 766 767**示例:** 768 769```ts 770import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 771import { BusinessError } from '@ohos.base'; 772 773//wantAgent对象 774let wantAgent1: _WantAgent; 775let wantAgent2: _WantAgent; 776 777//getWantAgent回调 778function getWantAgentCallback(err: BusinessError, data: _WantAgent) { 779 console.info('==========================>getWantAgentCallback=======================>'); 780 if (err.code == 0) { 781 wantAgent1 = data; 782 wantAgent2 = data; 783 } else { 784 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 785 return; 786 } 787 788 //equal回调 789 let equalCallback = (err: BusinessError, data: boolean) => { 790 console.info('==========================>equalCallback=======================>'); 791 } 792 WantAgent.equal(wantAgent1, wantAgent2, equalCallback) 793} 794 795WantAgent.getWantAgent({ 796 wants: [ 797 { 798 deviceId: 'deviceId', 799 bundleName: 'com.neu.setResultOnAbilityResultTest1', 800 abilityName: 'com.example.test.EntryAbility', 801 action: 'action1', 802 entities: ['entity1'], 803 type: 'MIMETYPE', 804 uri: 'key={true,true,false}', 805 parameters: 806 { 807 mykey0: 2222, 808 mykey1: [1, 2, 3], 809 mykey2: '[1, 2, 3]', 810 mykey3: 'ssssssssssssssssssssssssss', 811 mykey4: [false, true, false], 812 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 813 mykey6: true, 814 } 815 } 816 ], 817 operationType: WantAgent.OperationType.START_ABILITIES, 818 requestCode: 0, 819 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 820}, getWantAgentCallback) 821``` 822 823 824 825## WantAgent.equal 826 827equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\> 828 829判断两个WantAgent实例是否相等(Promise形式),以此来判断是否是来自同一应用的相同操作。 830 831**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 832 833**参数:** 834 835| 参数名 | 类型 | 必填 | 说明 | 836| ---------- | --------- | ---- | ------------- | 837| agent | WantAgent | 是 | WantAgent对象。 | 838| otherAgent | WantAgent | 是 | WantAgent对象。 | 839 840**返回值:** 841 842| 类型 | 说明 | 843| ----------------------------------------------------------- | ------------------------------------------------------------ | 844| Promise\<boolean\> | 以Promise形式返回获取判断两个WantAgent实例是否相等的结果。 | 845 846**示例:** 847 848```ts 849import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent'; 850import { BusinessError } from '@ohos.base'; 851 852 853//wantAgent对象 854let wantAgent1: _WantAgent; 855let wantAgent2: _WantAgent; 856 857WantAgent.getWantAgent({ 858 wants: [ 859 { 860 deviceId: 'deviceId', 861 bundleName: 'com.neu.setResultOnAbilityResultTest1', 862 abilityName: 'com.example.test.EntryAbility', 863 action: 'action1', 864 entities: ['entity1'], 865 type: 'MIMETYPE', 866 uri: 'key={true,true,false}', 867 parameters: 868 { 869 mykey0: 2222, 870 mykey1: [1, 2, 3], 871 mykey2: '[1, 2, 3]', 872 mykey3: 'ssssssssssssssssssssssssss', 873 mykey4: [false, true, false], 874 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 875 mykey6: true, 876 } 877 } 878 ], 879 operationType: WantAgent.OperationType.START_ABILITIES, 880 requestCode: 0, 881 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 882}).then((data) => { 883 console.info('==========================>getWantAgentCallback=======================>'); 884 wantAgent1 = data; 885 wantAgent2 = data; 886 if (data) { 887 WantAgent.equal(wantAgent1, wantAgent2).then((data) => { 888 console.info('==========================>equalCallback=======================>'); 889 }); 890 } 891}); 892``` 893 894## WantAgentFlags 895 896**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core 897 898| 名称 | 值 | 说明 | 899| ------------------- | -------------- | ------------------------------------------------------------ | 900| ONE_TIME_FLAG | 0 | WantAgent仅能使用一次。 | 901| NO_BUILD_FLAG | 1 | 如果说明WantAgent对象不存在,则不创建它,直接返回null。 | 902| CANCEL_PRESENT_FLAG | 2 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。 | 903| UPDATE_PRESENT_FLAG | 3 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。 | 904| CONSTANT_FLAG | 4 | WantAgent是不可变的。 | 905| REPLACE_ELEMENT | 5 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代 | 906| REPLACE_ACTION | 6 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代 | 907| REPLACE_URI | 7 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代 | 908| REPLACE_ENTITIES | 8 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代 | 909| REPLACE_BUNDLE | 9 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代 | 910 911## OperationType 912 913**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core 914 915| 名称 | 值 | 说明 | 916| ----------------- | ------------- | ------------------------- | 917| UNKNOWN_TYPE | 0 | 不识别的类型。 | 918| START_ABILITY | 1 | 开启一个有页面的Ability。 | 919| START_ABILITIES | 2 | 开启多个有页面的Ability。 | 920| START_SERVICE | 3 | 开启一个无页面的ability。 | 921| SEND_COMMON_EVENT | 4 | 发送一个公共事件。 | 922 923## CompleteData 924 925**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core 926 927| 名称 | 类型 | 必填 | 说明 | 928| -------------- | ------------------------------ | ---- | ---------------------- | 929| info | WantAgent | 是 | 触发的wantAgent。 | 930| want | Want | 是 | 存在的被触发的want。 | 931| finalCode | number | 是 | 触发wantAgent的请求代码。| 932| finalData | string | 是 | 公共事件收集的最终数据。 | 933| extraInfo | {[key: string]: any} | 否 | 额外数据。 | 934