• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.wantAgent (WantAgent)
2
3The **WantAgent** module provides APIs for creating and comparing **WantAgent** objects, and obtaining the user ID and bundle name of a **WantAgent** object.
4
5> **NOTE**
6>
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.
8
9## Modules to Import
10
11```ts
12import WantAgent from '@ohos.wantAgent';
13```
14
15## WantAgent.getWant
16
17getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void
18
19Obtains the Want in a **WantAgent** object. This API uses an asynchronous callback to return the result.
20
21**System capability**: SystemCapability.Ability.AbilityRuntime.Core
22
23**System API**: This is a system API and cannot be called by third-party applications.
24
25**Parameters**
26
27| Name    | Type                      | Mandatory| Description                   |
28| -------- | -------------------------- | ---- | ----------------------- |
29| agent     | [WantAgent](js-apis-wantAgent.md)              | Yes  | **WantAgent** object.          |
30| callback | AsyncCallback\<Want\> | Yes  | Callback used to return the Want.|
31
32**Example**
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 object
40let wantAgent: _WantAgent;
41
42// getWantAgent callback
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 callback
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
91Obtains the Want in a **WantAgent** object. This API uses a promise to return the result.
92
93**System capability**: SystemCapability.Ability.AbilityRuntime.Core
94
95**System API**: This is a system API and cannot be called by third-party applications.
96
97**Parameters**
98
99| Name| Type         | Mandatory| Description         |
100| ---- | ------------- | ---- | ------------- |
101| agent | [WantAgent](js-apis-wantAgent.md) | Yes  | **WantAgent** object.|
102
103**Return value**
104
105| Type                                                       | Description                                                        |
106| ----------------------------------------------------------- | ------------------------------------------------------------ |
107| Promise\<Want\> | Promise used to return the Want.|
108
109**Example**
110
111```ts
112import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
113import { BusinessError } from '@ohos.base';
114
115// WantAgent object
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
158Creates a **WantAgent** object. This API uses an asynchronous callback to return the result. If the creation fails, a null **WantAgent** object is returned.
159
160**System capability**: SystemCapability.Ability.AbilityRuntime.Core
161
162**Parameters**
163
164| Name    | Type                      | Mandatory| Description                   |
165| -------- | -------------------------- | ---- | ----------------------- |
166| info     | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md)              | Yes  | **WantAgent** object.          |
167| callback | AsyncCallback\<WantAgent\> | Yes  | Callback used to return the **WantAgent** object.|
168
169**Example**
170
171```ts
172import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
173import { BusinessError } from '@ohos.base';
174
175// getWantAgent callback
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
216Creates a **WantAgent** object. This API uses a promise to return the result. If the creation fails, a null **WantAgent** object is returned.
217
218**System capability**: SystemCapability.Ability.AbilityRuntime.Core
219
220**Parameters**
221
222| Name| Type         | Mandatory| Description         |
223| ---- | ------------- | ---- | ------------- |
224| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes  | **WantAgent** object.|
225
226**Return value**
227
228| Type                                                       | Description                                                        |
229| ----------------------------------------------------------- | ------------------------------------------------------------ |
230| Promise\<WantAgent\> | Promise used to return the **WantAgent** object.|
231
232**Example**
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
271Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous callback to return the result.
272
273**System capability**: SystemCapability.Ability.AbilityRuntime.Core
274
275**Parameters**
276
277| Name    | Type                   | Mandatory| Description                             |
278| -------- | ----------------------- | ---- | --------------------------------- |
279| agent    | WantAgent               | Yes  | **WantAgent** object.                    |
280| callback | AsyncCallback\<string\> | Yes  | Callback used to return the bundle name.|
281
282**Example**
283
284```ts
285import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
286import { BusinessError } from '@ohos.base';
287
288// WantAgent object
289let wantAgent: _WantAgent;
290
291// getWantAgent callback
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 callback
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
342Obtains the bundle name of a **WantAgent** object. This API uses a promise to return the result.
343
344**System capability**: SystemCapability.Ability.AbilityRuntime.Core
345
346**Parameters**
347
348| Name | Type     | Mandatory| Description         |
349| ----- | --------- | ---- | ------------- |
350| agent | WantAgent | Yes  | **WantAgent** object.|
351
352**Return value**
353
354| Type             | Description                                            |
355| ----------------- | ------------------------------------------------ |
356| Promise\<string\> | Promise used to return the bundle name.|
357
358**Example**
359
360```ts
361import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
362
363// WantAgent object
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
408Obtains the user ID of a **WantAgent** object. This API uses an asynchronous callback to return the result.
409
410**System capability**: SystemCapability.Ability.AbilityRuntime.Core
411
412**Parameters**
413
414| Name    | Type                   | Mandatory| Description                               |
415| -------- | ----------------------- | ---- | ----------------------------------- |
416| agent    | WantAgent               | Yes  | **WantAgent** object.                      |
417| callback | AsyncCallback\<number\> | Yes  | Callback used to return the user ID.|
418
419**Example**
420
421```ts
422import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
423import { BusinessError } from '@ohos.base';
424
425// WantAgent object
426let wantAgent: _WantAgent;
427
428// getWantAgent callback
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 callback
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
479Obtains the user ID of a **WantAgent** object. This API uses a promise to return the result.
480
481**System capability**: SystemCapability.Ability.AbilityRuntime.Core
482
483**Parameters**
484
485| Name | Type     | Mandatory| Description         |
486| ----- | --------- | ---- | ------------- |
487| agent | WantAgent | Yes  | **WantAgent** object.|
488
489**Return value**
490
491| Type                                                       | Description                                                        |
492| ----------------------------------------------------------- | ------------------------------------------------------------ |
493| Promise\<number\> | Promise used to return the user ID.|
494
495**Example**
496
497```ts
498import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
499
500// WantAgent object
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
544Cancels a **WantAgent** object. This API uses an asynchronous callback to return the result.
545
546**System capability**: SystemCapability.Ability.AbilityRuntime.Core
547
548**Parameters**
549
550| Name    | Type                 | Mandatory| Description                       |
551| -------- | --------------------- | ---- | --------------------------- |
552| agent    | WantAgent             | Yes  | **WantAgent** object.              |
553| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
554
555**Example**
556
557```ts
558import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
559import { BusinessError } from '@ohos.base';
560
561// WantAgent object
562let wantAgent: _WantAgent;
563
564// getWantAgent callback
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 callback
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
615Cancels a **WantAgent** object. This API uses a promise to return the result.
616
617**System capability**: SystemCapability.Ability.AbilityRuntime.Core
618
619**Parameters**
620
621| Name | Type     | Mandatory| Description         |
622| ----- | --------- | ---- | ------------- |
623| agent | WantAgent | Yes  | **WantAgent** object.|
624
625**Return value**
626
627| Type           | Description                           |
628| --------------- | ------------------------------- |
629| Promise\<void\> | Promise used to return the result.|
630
631**Example**
632
633```ts
634import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
635import { BusinessError } from '@ohos.base';
636
637// WantAgent object
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
682Triggers a **WantAgent** object. This API uses an asynchronous callback to return the result.
683
684**System capability**: SystemCapability.Ability.AbilityRuntime.Core
685
686**Parameters**
687
688| Name       | Type                         | Mandatory| Description                           |
689| ----------- | ----------------------------- | ---- | ------------------------------- |
690| agent       | WantAgent                     | Yes  | **WantAgent** object.                  |
691| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md)                     | Yes  | **TriggerInfo** object.                |
692| callback    | Callback\<CompleteData\> | No  | Callback used to return the result.|
693
694**Example**
695
696```ts
697import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
698import { BusinessError } from '@ohos.base';
699
700// WantAgent object
701let wantAgent: _WantAgent;
702
703// getWantAgent callback
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 callback
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
755Checks 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.
756
757**System capability**: SystemCapability.Ability.AbilityRuntime.Core
758
759**Parameters**
760
761| Name      | Type                    | Mandatory| Description                                   |
762| ---------- | ------------------------ | ---- | --------------------------------------- |
763| agent      | WantAgent                | Yes  | The first **WantAgent** object.                          |
764| otherAgent | WantAgent                | Yes  | The second **WantAgent** object.                          |
765| callback   | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|
766
767**Example**
768
769```ts
770import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
771import { BusinessError } from '@ohos.base';
772
773// WantAgent object
774let wantAgent1: _WantAgent;
775let wantAgent2: _WantAgent;
776
777// getWantAgent callback
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 callback
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
829Checks whether two **WantAgent** objects are equal to determine whether the same operation is from the same application. This API uses a promise to return the result.
830
831**System capability**: SystemCapability.Ability.AbilityRuntime.Core
832
833**Parameters**
834
835| Name      | Type     | Mandatory| Description         |
836| ---------- | --------- | ---- | ------------- |
837| agent      | WantAgent | Yes  | The first **WantAgent** object.|
838| otherAgent | WantAgent | Yes  | The second **WantAgent** object.|
839
840**Return value**
841
842| Type                                                       | Description                                                        |
843| ----------------------------------------------------------- | ------------------------------------------------------------ |
844| Promise\<boolean\> | Promise used to return the result.|
845
846**Example**
847
848```ts
849import WantAgent, { WantAgent as _WantAgent} from '@ohos.wantAgent';
850import { BusinessError } from '@ohos.base';
851
852
853// WantAgent object
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**System capability**: SystemCapability.Ability.AbilityRuntime.Core
897
898| Name               | Value            | Description                                                        |
899| ------------------- | -------------- | ------------------------------------------------------------ |
900| ONE_TIME_FLAG       | 0 | The **WantAgent** object can be used only once.                                     |
901| NO_BUILD_FLAG       | 1 | The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned.     |
902| CANCEL_PRESENT_FLAG | 2 | The existing **WantAgent** object should be canceled before a new object is generated.|
903| UPDATE_PRESENT_FLAG | 3 | Extra information of the existing **WantAgent** object is replaced with that of the new object.|
904| CONSTANT_FLAG       | 4 | The **WantAgent** object is immutable.                                       |
905| REPLACE_ELEMENT     | 5 | The **element** attribute of the current **Want** can be replaced by the **element** attribute of the **Want** in **WantAgent.trigger()**.|
906| REPLACE_ACTION      | 6 | The **action** attribute of the current **Want** can be replaced by the **action** attribute of the **Want** in **WantAgent.trigger()**.|
907| REPLACE_URI         | 7 | The **uri** attribute of the current **Want** can be replaced by the **uri** attribute of the **Want** in **WantAgent.trigger()**.|
908| REPLACE_ENTITIES    | 8 | The **entities** attribute of the current **Want** can be replaced by the **entities** attribute of the **Want** in **WantAgent.trigger()**.|
909| REPLACE_BUNDLE      | 9 | The **bundleName** attribute of the current **Want** can be replaced by the **bundleName** attribute of **Want** in **WantAgent.trigger()**.|
910
911## OperationType
912
913**System capability**: SystemCapability.Ability.AbilityRuntime.Core
914
915| Name             | Value           | Description                     |
916| ----------------- | ------------- | ------------------------- |
917| UNKNOWN_TYPE      | 0 | Unknown operation type.           |
918| START_ABILITY     | 1 | Starts an ability with a UI.|
919| START_ABILITIES   | 2 | Starts multiple abilities with a UI.|
920| START_SERVICE     | 3 | Starts an ability without a UI.|
921| SEND_COMMON_EVENT | 4 | Sends a common event.       |
922
923## CompleteData
924
925**System capability**: SystemCapability.Ability.AbilityRuntime.Core
926
927| Name          | Type                          | Mandatory| Description                   |
928| -------------- | ------------------------------ | ---- | ---------------------- |
929| info           | WantAgent                       | Yes  | A triggered **WantAgent** object.      |
930| want           | Want                            | Yes  | An existing triggered **want**.    |
931| finalCode      | number                          | Yes  | Request code that triggers the **WantAgent** object.|
932| finalData      | string                          | Yes  | Final data collected by the common event. |
933| extraInfo      | {[key: string]: any}            | No  | Extra information.              |
934