js-apis-wantAgent.md 30.4 KB
Newer Older
1
# @ohos.wantAgent
W
wusongqing 已提交
2

3
The **WantAgent** module provides APIs for creating and comparing **WantAgent** objects, and obtaining the user ID and bundle name of a **WantAgent** object.
4

W
wusongqing 已提交
5 6
> **NOTE**
> 
7
> The APIs of this module are supported since API version 7 and deprecated since API version 9. You are advised to use [@ohos.app.ability.wantAgent](js-apis-app-ability-wantAgent.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
8 9 10

## Modules to Import

11
```ts
W
wusongqing 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24
import WantAgent from '@ohos.wantAgent';
```

## WantAgent.getWantAgent

getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void

Obtains a **WantAgent** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

25 26
| Name    | Type                      | Mandatory| Description                   |
| -------- | -------------------------- | ---- | ----------------------- |
27
| info     | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md)              | Yes  | Information about the **WantAgent** object to obtain.          |
28
| callback | AsyncCallback\<WantAgent\> | Yes  | Callback used to return the **WantAgent** object.|
W
wusongqing 已提交
29 30 31

**Example**

32
```ts
W
wusongqing 已提交
33 34 35 36
import WantAgent from '@ohos.wantAgent';

// getWantAgent callback
function getWantAgentCallback(err, data) {
37 38 39 40 41
    if (err.code) {
        console.info('getWantAgent Callback err:' + JSON.stringify(err))
    } else { 
        console.info('getWantAgent Callback success')
    }
W
wusongqing 已提交
42 43
}
// WantAgentInfo object
44
let wantAgentInfo = {
W
wusongqing 已提交
45 46
    wants: [
        {
47 48 49 50 51 52 53
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
54 55 56 57
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
58 59
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
60
                mykey4: [false, true, false],
61
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
62 63 64 65
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
66
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
67
    requestCode: 0,
W
wusongqing 已提交
68
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
69 70
}

71
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
W
wusongqing 已提交
72 73 74 75 76 77 78 79 80 81 82 83
```

## WantAgent.getWantAgent

getWantAgent(info: WantAgentInfo): Promise\<WantAgent\>

Obtains a **WantAgent** object. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

84 85
| Name| Type         | Mandatory| Description         |
| ---- | ------------- | ---- | ------------- |
86
| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes  | Information about the **WantAgent** object to obtain.|
W
wusongqing 已提交
87 88 89 90 91 92 93 94 95

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<WantAgent\> | Promise used to return the **WantAgent** object.|

**Example**

96
```ts
W
wusongqing 已提交
97
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
98

W
wusongqing 已提交
99 100

// WantAgentInfo object
101
let wantAgentInfo = {
W
wusongqing 已提交
102 103
    wants: [
        {
104 105 106 107 108 109 110
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
111 112 113 114
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
115 116
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
117
                mykey4: [false, true, false],
118
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
119 120 121 122
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
123
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
124
    requestCode: 0,
W
wusongqing 已提交
125
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
126 127 128
}

WantAgent.getWantAgent(wantAgentInfo).then((data) => {
129
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142
});
```

## WantAgent.getBundleName

getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void

Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

143 144 145 146
| Name    | Type                   | Mandatory| Description                             |
| -------- | ----------------------- | ---- | --------------------------------- |
| agent    | WantAgent               | Yes  | Target **WantAgent** object.                    |
| callback | AsyncCallback\<string\> | Yes  | Callback used to return the bundle name.|
W
wusongqing 已提交
147 148 149

**Example**

150
```ts
W
wusongqing 已提交
151
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
152

W
wusongqing 已提交
153 154

// WantAgent object
155
let wantAgent;
W
wusongqing 已提交
156 157 158

// getWantAgent callback
function getWantAgentCallback(err, data) {
159
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
160 161 162 163 164 165 166
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
// WantAgentInfo object
167
let wantAgentInfo = {
W
wusongqing 已提交
168 169
    wants: [
        {
170 171 172 173 174 175 176
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
177 178 179 180
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
181 182
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
183
                mykey4: [false, true, false],
184
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
185 186 187 188
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
189
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
190
    requestCode: 0,
W
wusongqing 已提交
191
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
192 193 194 195 196 197
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

// getBundleName callback
function getBundleNameCallback(err, data) {
198
	console.info('==========================>getBundleNameCallback=======================>');
W
wusongqing 已提交
199
}
200
WantAgent.getBundleName(wantAgent, getBundleNameCallback);
W
wusongqing 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214
```



## WantAgent.getBundleName

getBundleName(agent: WantAgent): Promise\<string\>

Obtains the bundle name of a **WantAgent** object. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

215 216 217
| Name | Type     | Mandatory| Description         |
| ----- | --------- | ---- | ------------- |
| agent | WantAgent | Yes  | Target **WantAgent** object.|
W
wusongqing 已提交
218 219 220

**Return value**

221 222
| Type             | Description                                            |
| ----------------- | ------------------------------------------------ |
W
wusongqing 已提交
223 224 225 226
| Promise\<string\> | Promise used to return the bundle name.|

**Example**

227
```ts
W
wusongqing 已提交
228
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
229

W
wusongqing 已提交
230
// WantAgent object
231
let wantAgent;
W
wusongqing 已提交
232 233

// WantAgentInfo object
234
let wantAgentInfo = {
W
wusongqing 已提交
235 236
    wants: [
        {
237 238 239 240 241 242 243
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
244 245 246 247
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
248 249
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
250
                mykey4: [false, true, false],
251
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
252 253 254 255
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
256
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
257
    requestCode: 0,
W
wusongqing 已提交
258
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
259 260 261
}

WantAgent.getWantAgent(wantAgentInfo).then((data) => {
262
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
263 264 265 266
    wantAgent = data;
});

WantAgent.getBundleName(wantAgent).then((data) => {
267
	console.info('==========================>getBundleNameCallback=======================>');
W
wusongqing 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
});
```



## WantAgent.getUid

getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void

Obtains the user ID of a **WantAgent** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

283 284 285 286
| Name    | Type                   | Mandatory| Description                               |
| -------- | ----------------------- | ---- | ----------------------------------- |
| agent    | WantAgent               | Yes  | Target **WantAgent** object.                      |
| callback | AsyncCallback\<number\> | Yes  | Callback used to return the user ID.|
W
wusongqing 已提交
287 288 289

**Example**

290
```ts
W
wusongqing 已提交
291
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
292

W
wusongqing 已提交
293 294

// WantAgent object
295
let wantAgent;
W
wusongqing 已提交
296 297 298

// getWantAgent callback
function getWantAgentCallback(err, data) {
299
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
300 301 302 303 304 305 306
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
// WantAgentInfo object
307
let wantAgentInfo = {
W
wusongqing 已提交
308 309
    wants: [
        {
310 311 312 313 314 315 316
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
317 318 319 320
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
321 322
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
323
                mykey4: [false, true, false],
324
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
325 326 327 328
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
329
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
330
    requestCode: 0,
W
wusongqing 已提交
331
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
332 333 334 335 336 337
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

// getUid callback
function getUidCallback(err, data) {
338
	console.info('==========================>getUidCallback=======================>');
W
wusongqing 已提交
339
}
340
WantAgent.getUid(wantAgent, getUidCallback);
W
wusongqing 已提交
341 342 343 344 345 346 347 348 349 350 351 352 353 354
```



## WantAgent.getUid

getUid(agent: WantAgent): Promise\<number\>

Obtains the user ID of a **WantAgent** object. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

355 356 357
| Name | Type     | Mandatory| Description         |
| ----- | --------- | ---- | ------------- |
| agent | WantAgent | Yes  | Target **WantAgent** object.|
W
wusongqing 已提交
358 359 360 361 362 363 364 365 366

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number\> | Promise used to return the user ID.|

**Example**

367
```ts
W
wusongqing 已提交
368
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
369

W
wusongqing 已提交
370 371

// WantAgent object
372
let wantAgent;
W
wusongqing 已提交
373 374

// WantAgentInfo object
375
let wantAgentInfo = {
W
wusongqing 已提交
376 377
    wants: [
        {
378 379 380 381 382 383 384
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
385 386 387 388
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
389 390
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
391
                mykey4: [false, true, false],
392
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
393 394 395 396
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
397
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
398
    requestCode: 0,
W
wusongqing 已提交
399
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
400 401 402
}

WantAgent.getWantAgent(wantAgentInfo).then((data) => {
403
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
404 405 406 407
    wantAgent = data;
});

WantAgent.getUid(wantAgent).then((data) => {
408
	console.info('==========================>getUidCallback=======================>');
W
wusongqing 已提交
409 410 411 412 413 414 415 416 417 418 419 420 421 422
});
```


## WantAgent.cancel

cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void

Cancels a **WantAgent** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

423 424 425 426
| Name    | Type                 | Mandatory| Description                       |
| -------- | --------------------- | ---- | --------------------------- |
| agent    | WantAgent             | Yes  | Target **WantAgent** object.              |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
427 428 429

**Example**

430
```ts
W
wusongqing 已提交
431
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
432

W
wusongqing 已提交
433 434

// WantAgent object
435
let wantAgent;
W
wusongqing 已提交
436 437 438

// getWantAgent callback
function getWantAgentCallback(err, data) {
439
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
440 441 442 443 444 445 446
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
// WantAgentInfo object
447
let wantAgentInfo = {
W
wusongqing 已提交
448 449
    wants: [
        {
450 451 452 453 454 455 456
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
457 458 459 460
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
461 462
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
463
                mykey4: [false, true, false],
464
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
465 466 467 468
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
469
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
470
    requestCode: 0,
W
wusongqing 已提交
471
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
472 473 474 475 476 477
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

// cancel callback
function cancelCallback(err, data) {
478
	console.info('==========================>cancelCallback=======================>');
W
wusongqing 已提交
479
}
480
WantAgent.cancel(wantAgent, cancelCallback);
W
wusongqing 已提交
481 482 483 484 485 486 487 488 489 490 491 492 493 494
```



## WantAgent.cancel

cancel(agent: WantAgent): Promise\<void\>

Cancels a **WantAgent** object. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

495 496 497
| Name | Type     | Mandatory| Description         |
| ----- | --------- | ---- | ------------- |
| agent | WantAgent | Yes  | Target **WantAgent** object.|
W
wusongqing 已提交
498 499 500 501 502 503

**Return value**

| Type           | Description                           |
| --------------- | ------------------------------- |
| Promise\<void\> | Promise used to return the result.|
W
wusongqing 已提交
504 505 506

**Example**

507
```ts
W
wusongqing 已提交
508
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
509

W
wusongqing 已提交
510 511

// WantAgent object
512
let wantAgent;
W
wusongqing 已提交
513 514

// WantAgentInfo object
515
let wantAgentInfo = {
W
wusongqing 已提交
516 517
    wants: [
        {
518 519 520 521 522 523 524
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
525 526 527 528
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
529 530
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
531
                mykey4: [false, true, false],
532
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
533 534 535 536
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
537
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
538
    requestCode: 0,
W
wusongqing 已提交
539
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
540 541 542
}

WantAgent.getWantAgent(wantAgentInfo).then((data) => {
543
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
544 545 546 547
    wantAgent = data;
});

WantAgent.cancel(wantAgent).then((data) => {
548
	console.info('==========================>cancelCallback=======================>');
W
wusongqing 已提交
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
});
```



## WantAgent.trigger

trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>): void

Triggers a **WantAgent** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

564 565 566
| Name       | Type                         | Mandatory| Description                           |
| ----------- | ----------------------------- | ---- | ------------------------------- |
| agent       | WantAgent                     | Yes  | Target **WantAgent** object.                  |
567
| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md)                     | Yes  | **TriggerInfo** object.                |
568
| callback    | AsyncCallback\<CompleteData\> | No  | Callback used to return the result.|
W
wusongqing 已提交
569 570 571

**Example**

572
```ts
W
wusongqing 已提交
573
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
574

W
wusongqing 已提交
575 576

// WantAgent object
577
let wantAgent;
W
wusongqing 已提交
578 579 580

// getWantAgent callback
function getWantAgentCallback(err, data) {
581
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
582 583 584 585 586 587 588
    if (err.code == 0) {
    	wantAgent = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
// WantAgentInfo object
589
let wantAgentInfo = {
W
wusongqing 已提交
590 591
    wants: [
        {
592 593 594 595 596 597 598
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
599 600 601 602
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
603 604
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
605
                mykey4: [false, true, false],
606
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
607 608 609 610
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
611
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
612
    requestCode: 0,
W
wusongqing 已提交
613
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
614 615 616 617 618
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

// trigger callback
W
wusongqing 已提交
619
function triggerCallback(data) {
620
	console.info('==========================>triggerCallback=======================>');
W
wusongqing 已提交
621 622 623 624 625 626 627 628 629 630 631 632 633 634
}

var triggerInfo = {
    code:0
}
WantAgent.trigger(wantAgent, triggerInfo, triggerCallback)
```



## WantAgent.equal

equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void

635
Checks whether two **WantAgent** objects are equal to determine whether the same operation is from the same application. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
636 637 638 639 640

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

641 642 643 644 645
| Name      | Type                    | Mandatory| Description                                   |
| ---------- | ------------------------ | ---- | --------------------------------------- |
| agent      | WantAgent                | Yes  | The first **WantAgent** object.                          |
| otherAgent | WantAgent                | Yes  | The second **WantAgent** object.                          |
| callback   | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
646 647 648

**Example**

649
```ts
W
wusongqing 已提交
650
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
651

W
wusongqing 已提交
652 653

// WantAgent object
654 655
let wantAgent1;
let wantAgent2;
W
wusongqing 已提交
656 657 658

// getWantAgent callback
function getWantAgentCallback(err, data) {
659
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
660 661 662 663 664 665 666 667
    if (err.code == 0) {
    	wantAgent1 = data;
        wantAgent2 = data;
    } else {
        console.info('----getWantAgent failed!----');
    }
}
// WantAgentInfo object
668
let wantAgentInfo = {
W
wusongqing 已提交
669 670
    wants: [
        {
671 672 673 674 675 676 677
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
678 679 680 681
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
682 683
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
684
                mykey4: [false, true, false],
685
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
686 687 688 689
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
690
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
691
    requestCode: 0,
W
wusongqing 已提交
692
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
693 694 695 696 697 698
}

WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)

// equal callback
function equalCallback(err, data) {
699
	console.info('==========================>equalCallback=======================>');
W
wusongqing 已提交
700 701 702 703 704 705 706 707 708 709
}
WantAgent.equal(wantAgent1, wantAgent2, equalCallback)
```



## WantAgent.equal

equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>

710
Checks whether two **WantAgent** objects are equal to determine whether the same operation is from the same application. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
711 712 713 714 715

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

716 717 718 719
| Name      | Type     | Mandatory| Description         |
| ---------- | --------- | ---- | ------------- |
| agent      | WantAgent | Yes  | The first **WantAgent** object.|
| otherAgent | WantAgent | Yes  | The second **WantAgent** object.|
W
wusongqing 已提交
720 721 722 723 724 725 726 727 728

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|

**Example**

729
```ts
W
wusongqing 已提交
730
import WantAgent from '@ohos.wantAgent';
W
wusongqing 已提交
731

W
wusongqing 已提交
732 733

// WantAgent object
734 735
let wantAgent1;
let wantAgent2;
W
wusongqing 已提交
736 737

// WantAgentInfo object
738
let wantAgentInfo = {
W
wusongqing 已提交
739 740
    wants: [
        {
741 742 743 744 745 746 747
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
748 749 750 751
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
752 753
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
754
                mykey4: [false, true, false],
755
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
756 757 758 759
                mykey6: true,
            }
        }
    ],
W
wusongqing 已提交
760
    operationType: WantAgent.OperationType.START_ABILITIES,
W
wusongqing 已提交
761
    requestCode: 0,
W
wusongqing 已提交
762
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
W
wusongqing 已提交
763 764 765
}

WantAgent.getWantAgent(wantAgentInfo).then((data) => {
766
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
767 768 769 770 771
    wantAgent1 = data;
    wantAgent2 = data;
});

WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
772
	console.info('==========================>equalCallback=======================>');
W
wusongqing 已提交
773 774 775
});
```

W
wusongqing 已提交
776
## WantAgent.getOperationType<sup>9+</sup>
W
wusongqing 已提交
777 778 779 780 781 782 783 784 785

getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void;

Obtains the operation type of a **WantAgent** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

786 787 788 789
| Name      | Type                    | Mandatory| Description                                   |
| ---------- | ------------------------ | ---- | --------------------------------------- |
| agent      | WantAgent                | Yes  | Target **WantAgent** object.                          |
| callback   | AsyncCallback\<number> | Yes  | Callback used to return the operation type.|
W
wusongqing 已提交
790 791 792

**Example**

793
```ts
W
wusongqing 已提交
794 795 796
import WantAgent from '@ohos.wantAgent';

// WantAgent object
797
let wantAgent;
W
wusongqing 已提交
798 799

// WantAgentInfo object
800
let wantAgentInfo = {
W
wusongqing 已提交
801 802
    wants: [
        {
803 804 805 806 807 808 809
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
810 811 812 813
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
814 815
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
816
                mykey4: [false, true, false],
817
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
818 819 820 821 822 823 824 825 826 827
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) => {
828
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
829 830 831 832 833 834 835 836
    wantAgent = data;
});

WantAgent.getOperationType(wantAgent, (OperationType) => {
    console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
})
```

W
wusongqing 已提交
837
## WantAgent.getOperationType<sup>9+</sup>
W
wusongqing 已提交
838 839 840 841 842 843 844 845 846

getOperationType(agent: WantAgent): Promise\<number>;

Obtains the operation type of a **WantAgent** object. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

847 848 849
| Name      | Type     | Mandatory| Description         |
| ---------- | --------- | ---- | ------------- |
| agent      | WantAgent | Yes  | Target **WantAgent** object.|
W
wusongqing 已提交
850 851 852 853 854 855 856 857 858

**Return value**

| Type                                                       | Description                                                        |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number> | Promise used to return the operation type.|

**Example**

859
```ts
W
wusongqing 已提交
860 861 862
import WantAgent from '@ohos.wantAgent';

// WantAgent object
863
let wantAgent;
W
wusongqing 已提交
864 865

// WantAgentInfo object
866
let wantAgentInfo = {
W
wusongqing 已提交
867 868
    wants: [
        {
869 870 871 872 873 874 875
            deviceId: 'deviceId',
            bundleName: 'com.neu.setResultOnAbilityResultTest1',
            abilityName: 'com.example.test.EntryAbility',
            action: 'action1',
            entities: ['entity1'],
            type: 'MIMETYPE',
            uri: 'key={true,true,false}',
W
wusongqing 已提交
876 877 878 879
            parameters:
            {
                mykey0: 2222,
                mykey1: [1, 2, 3],
880 881
                mykey2: '[1, 2, 3]',
                mykey3: 'ssssssssssssssssssssssssss',
W
wusongqing 已提交
882
                mykey4: [false, true, false],
883
                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
W
wusongqing 已提交
884 885 886 887 888 889 890 891 892 893
                mykey6: true,
            }
        }
    ],
    operationType: WantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

WantAgent.getWantAgent(wantAgentInfo).then((data) => {
894
	console.info('==========================>getWantAgentCallback=======================>');
W
wusongqing 已提交
895
    wantAgent = data;
896 897 898 899 900
    WantAgent.getOperationType(wantAgent).then((OperationType) => {
        console.log('getOperationType success, OperationType: ' + OperationType);
    }).catch((err) => {
        console.log('getOperationType fail, err: ' + err);
    })
W
wusongqing 已提交
901 902 903
});
```

W
wusongqing 已提交
904 905 906 907 908 909 910

## WantAgentFlags

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

| Name               | Value            | Description                                                        |
| ------------------- | -------------- | ------------------------------------------------------------ |
911 912 913 914 915 916 917 918 919 920
| ONE_TIME_FLAG       | 0 | The **WantAgent** object can be used only once.                                     |
| NO_BUILD_FLAG       | 1 | The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned.     |
| CANCEL_PRESENT_FLAG | 2 | The existing **WantAgent** object should be canceled before a new object is generated.|
| UPDATE_PRESENT_FLAG | 3 | Extra information of the existing **WantAgent** object is replaced with that of the new object.|
| CONSTANT_FLAG       | 4 | The **WantAgent** object is immutable.                                       |
| REPLACE_ELEMENT     | 5 | The **element** attribute of the current **Want** can be replaced by the **element** attribute of the **Want** in **WantAgent.trigger()**.|
| REPLACE_ACTION      | 6 | The **action** attribute of the current **Want** can be replaced by the **action** attribute of the **Want** in **WantAgent.trigger()**.|
| REPLACE_URI         | 7 | The **uri** attribute of the current **Want** can be replaced by the **uri** attribute of the **Want** in **WantAgent.trigger()**.|
| REPLACE_ENTITIES    | 8 | The **entities** attribute of the current **Want** can be replaced by the **entities** attribute of the **Want** in **WantAgent.trigger()**.|
| REPLACE_BUNDLE      | 9 | The **bundleName** attribute of the current **Want** can be replaced by the **bundleName** attribute of **Want** in **WantAgent.trigger()**.|
W
wusongqing 已提交
921 922 923 924 925 926 927

## OperationType

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

| Name             | Value           | Description                     |
| ----------------- | ------------- | ------------------------- |
928 929 930 931 932
| UNKNOWN_TYPE      | 0 | Unknown operation type.           |
| START_ABILITY     | 1 | Starts an ability with a UI.|
| START_ABILITIES   | 2 | Starts multiple abilities with a UI.|
| START_SERVICE     | 3 | Starts an ability without a UI.|
| SEND_COMMON_EVENT | 4 | Sends a common event.       |
W
wusongqing 已提交
933 934 935 936 937

## CompleteData 

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

938 939 940 941 942 943 944
| Name          | Type                          | Mandatory| Description                   |
| -------------- | ------------------------------ | ---- | ---------------------- |
| info           | WantAgent                       | Yes  | A triggered **WantAgent** object.      |
| want           | Want                            | Yes  | An existing triggered **want**.    |
| finalCode      | number                          | Yes  | Request code that triggers the **WantAgent** object.|
| finalData      | string                          | No  | Final data collected by the common event. |
| extraInfo      | {[key: string]: any}            | No  | Extra information.              |