• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.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. You are advised to use this module, since it will replace the [@ohos.wantAgent](js-apis-wantAgent.md) module in the near future.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```js
12import WantAgent from '@ohos.app.ability.wantAgent';
13```
14
15## WantAgent.getWantAgent
16
17getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void
18
19Obtains a **WantAgent** object. This API uses an asynchronous callback to return the result. If the creation fails, a null **WantAgent** object is returned.
20
21**System capability**: SystemCapability.Ability.AbilityRuntime.Core
22
23**Parameters**
24
25| Name    | Type                      | Mandatory| Description                   |
26| -------- | -------------------------- | ---- | ----------------------- |
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.|
29
30**Example**
31
32```js
33import WantAgent from '@ohos.app.ability.wantAgent';
34
35// getWantAgent callback
36function getWantAgentCallback(err, data) {
37	console.info('==========================>getWantAgentCallback=======================>');
38}
39// WantAgentInfo object
40let wantAgentInfo = {
41    wants: [
42        {
43            deviceId: 'deviceId',
44            bundleName: 'com.neu.setResultOnAbilityResultTest1',
45            abilityName: 'com.example.test.MainAbility',
46            action: 'action1',
47            entities: ['entity1'],
48            type: 'MIMETYPE',
49            uri: 'key={true,true,false}',
50            parameters:
51            {
52                mykey0: 2222,
53                mykey1: [1, 2, 3],
54                mykey2: '[1, 2, 3]',
55                mykey3: 'ssssssssssssssssssssssssss',
56                mykey4: [false, true, false],
57                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
58                mykey6: true,
59            }
60        }
61    ],
62    operationType: WantAgent.OperationType.START_ABILITIES,
63    requestCode: 0,
64    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
65};
66
67try {
68    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
69} catch (paramError) {
70    console.log('error: ' + paramError.code + ', ' + paramError.message);
71}
72```
73
74
75
76## WantAgent.getWantAgent
77
78getWantAgent(info: WantAgentInfo): Promise\<WantAgent\>
79
80Obtains a **WantAgent** object. This API uses a promise to return the result. If the creation fails, a null **WantAgent** object is returned.
81
82**System capability**: SystemCapability.Ability.AbilityRuntime.Core
83
84**Parameters**
85
86| Name| Type         | Mandatory| Description         |
87| ---- | ------------- | ---- | ------------- |
88| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes  | Information about the **WantAgent** object to obtain.|
89
90**Return value**
91
92| Type                                                       | Description                                                        |
93| ----------------------------------------------------------- | ------------------------------------------------------------ |
94| Promise\<WantAgent\> | Promise used to return the **WantAgent** object.|
95
96**Example**
97
98```js
99import WantAgent from '@ohos.app.ability.wantAgent';
100
101
102// WantAgentInfo object
103let wantAgentInfo = {
104    wants: [
105        {
106            deviceId: 'deviceId',
107            bundleName: 'com.neu.setResultOnAbilityResultTest1',
108            abilityName: 'com.example.test.MainAbility',
109            action: 'action1',
110            entities: ['entity1'],
111            type: 'MIMETYPE',
112            uri: 'key={true,true,false}',
113            parameters:
114            {
115                mykey0: 2222,
116                mykey1: [1, 2, 3],
117                mykey2: '[1, 2, 3]',
118                mykey3: 'ssssssssssssssssssssssssss',
119                mykey4: [false, true, false],
120                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
121                mykey6: true,
122            }
123        }
124    ],
125    operationType: WantAgent.OperationType.START_ABILITIES,
126    requestCode: 0,
127    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
128};
129
130try {
131    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
132	    console.info('==========================>getWantAgentCallback=======================>');
133    });
134} catch (paramError) {
135    console.log('error: ' + paramError.code + ', ' + paramError.message);
136}
137```
138
139
140
141## WantAgent.getBundleName
142
143getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void
144
145Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous callback to return the result.
146
147**System capability**: SystemCapability.Ability.AbilityRuntime.Core
148
149**Parameters**
150
151| Name    | Type                   | Mandatory| Description                             |
152| -------- | ----------------------- | ---- | --------------------------------- |
153| agent    | WantAgent               | Yes  | Target **WantAgent** object.                    |
154| callback | AsyncCallback\<string\> | Yes  | Callback used to return the bundle name.|
155
156**Example**
157
158```js
159import WantAgent from '@ohos.app.ability.wantAgent';
160
161
162// wantAgent object
163let wantAgent;
164
165//getWantAgent callback
166function getWantAgentCallback(err, data) {
167	console.info('==========================>getWantAgentCallback=======================>');
168    if (err.code == 0) {
169    	wantAgent = data;
170    } else {
171        console.info('----getWantAgent failed!----');
172    }
173}
174// WantAgentInfo object
175let wantAgentInfo = {
176    wants: [
177        {
178            deviceId: 'deviceId',
179            bundleName: 'com.neu.setResultOnAbilityResultTest1',
180            abilityName: 'com.example.test.MainAbility',
181            action: 'action1',
182            entities: ['entity1'],
183            type: 'MIMETYPE',
184            uri: 'key={true,true,false}',
185            parameters:
186            {
187                mykey0: 2222,
188                mykey1: [1, 2, 3],
189                mykey2: '[1, 2, 3]',
190                mykey3: 'ssssssssssssssssssssssssss',
191                mykey4: [false, true, false],
192                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
193                mykey6: true,
194            }
195        }
196    ],
197    operationType: WantAgent.OperationType.START_ABILITIES,
198    requestCode: 0,
199    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
200};
201
202try {
203    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
204
205    // getBundleName callback
206    function getBundleNameCallback(err, data) {
207	    console.info('==========================>getBundleNameCallback=======================>');
208    }
209    WantAgent.getBundleName(wantAgent, getBundleNameCallback);
210} catch (paramError) {
211    console.log('error: ' + paramError.code + ', ' + paramError.message);
212}
213```
214
215
216
217## WantAgent.getBundleName
218
219getBundleName(agent: WantAgent): Promise\<string\>
220
221Obtains the bundle name of a **WantAgent** object. This API uses a promise to return the result.
222
223**System capability**: SystemCapability.Ability.AbilityRuntime.Core
224
225**Parameters**
226
227| Name | Type     | Mandatory| Description         |
228| ----- | --------- | ---- | ------------- |
229| agent | WantAgent | Yes  | Target **WantAgent** object.|
230
231**Return value**
232
233| Type                                                       | Description                                                        |
234| ----------------------------------------------------------- | ------------------------------------------------------------ |
235| Promise\<string\> | Promise used to return the bundle name.|
236
237**Example**
238
239```js
240import WantAgent from '@ohos.app.ability.wantAgent';
241
242
243// wantAgent object
244let wantAgent;
245
246//WantAgentInfo object
247let wantAgentInfo = {
248    wants: [
249        {
250            deviceId: 'deviceId',
251            bundleName: 'com.neu.setResultOnAbilityResultTest1',
252            abilityName: 'com.example.test.MainAbility',
253            action: 'action1',
254            entities: ['entity1'],
255            type: 'MIMETYPE',
256            uri: 'key={true,true,false}',
257            parameters:
258            {
259                mykey0: 2222,
260                mykey1: [1, 2, 3],
261                mykey2: '[1, 2, 3]',
262                mykey3: 'ssssssssssssssssssssssssss',
263                mykey4: [false, true, false],
264                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
265                mykey6: true,
266            }
267        }
268    ],
269    operationType: WantAgent.OperationType.START_ABILITIES,
270    requestCode: 0,
271    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
272};
273
274try {
275    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
276	    console.info('==========================>getWantAgentCallback=======================>');
277        wantAgent = data;
278    });
279
280    WantAgent.getBundleName(wantAgent).then((data) => {
281	    console.info('==========================>getBundleNameCallback=======================>');
282    });
283} catch (paramError) {
284    console.log('error: ' + paramError.code + ', ' + paramError.message);
285}
286```
287
288
289
290## WantAgent.getUid
291
292getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void
293
294Obtains the user ID of a **WantAgent** object. This API uses an asynchronous callback to return the result.
295
296**System capability**: SystemCapability.Ability.AbilityRuntime.Core
297
298**Parameters**
299
300| Name    | Type                   | Mandatory| Description                               |
301| -------- | ----------------------- | ---- | ----------------------------------- |
302| agent    | WantAgent               | Yes  | Target **WantAgent** object.                      |
303| callback | AsyncCallback\<number\> | Yes  | Callback used to return the user ID.|
304
305**Example**
306
307```js
308import WantAgent from '@ohos.app.ability.wantAgent';
309
310
311// wantAgent object
312let wantAgent;
313
314// getWantAgent callback
315function getWantAgentCallback(err, data) {
316	console.info('==========================>getWantAgentCallback=======================>');
317    if (err.code == 0) {
318    	wantAgent = data;
319    } else {
320        console.info('----getWantAgent failed!----');
321    }
322}
323// WantAgentInfo object
324let wantAgentInfo = {
325    wants: [
326        {
327            deviceId: 'deviceId',
328            bundleName: 'com.neu.setResultOnAbilityResultTest1',
329            abilityName: 'com.example.test.MainAbility',
330            action: 'action1',
331            entities: ['entity1'],
332            type: 'MIMETYPE',
333            uri: 'key={true,true,false}',
334            parameters:
335            {
336                mykey0: 2222,
337                mykey1: [1, 2, 3],
338                mykey2: '[1, 2, 3]',
339                mykey3: 'ssssssssssssssssssssssssss',
340                mykey4: [false, true, false],
341                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
342                mykey6: true,
343            }
344        }
345    ],
346    operationType: WantAgent.OperationType.START_ABILITIES,
347    requestCode: 0,
348    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
349};
350
351try {
352    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
353
354    // getUid callback
355    function getUidCallback(err, data) {
356	    console.info('==========================>getUidCallback=======================>');
357    }
358    WantAgent.getUid(wantAgent, getUidCallback);
359} catch (paramError) {
360    console.log('error: ' + paramError.code + ', ' + paramError.message);
361}
362```
363
364
365
366## WantAgent.getUid
367
368getUid(agent: WantAgent): Promise\<number\>
369
370Obtains the user ID of a **WantAgent** object. This API uses a promise to return the result.
371
372**System capability**: SystemCapability.Ability.AbilityRuntime.Core
373
374**Parameters**
375
376| Name | Type     | Mandatory| Description         |
377| ----- | --------- | ---- | ------------- |
378| agent | WantAgent | Yes  | Target **WantAgent** object.|
379
380**Return value**
381
382| Type                                                       | Description                                                        |
383| ----------------------------------------------------------- | ------------------------------------------------------------ |
384| Promise\<number\> | Promise used to return the user ID.|
385
386**Example**
387
388```js
389import WantAgent from '@ohos.app.ability.wantAgent';
390
391
392// wantAgent object
393let wantAgent;
394
395// WantAgentInfo object
396let wantAgentInfo = {
397    wants: [
398        {
399            deviceId: 'deviceId',
400            bundleName: 'com.neu.setResultOnAbilityResultTest1',
401            abilityName: 'com.example.test.MainAbility',
402            action: 'action1',
403            entities: ['entity1'],
404            type: 'MIMETYPE',
405            uri: 'key={true,true,false}',
406            parameters:
407            {
408                mykey0: 2222,
409                mykey1: [1, 2, 3],
410                mykey2: '[1, 2, 3]',
411                mykey3: 'ssssssssssssssssssssssssss',
412                mykey4: [false, true, false],
413                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
414                mykey6: true,
415            }
416        }
417    ],
418    operationType: WantAgent.OperationType.START_ABILITIES,
419    requestCode: 0,
420    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
421};
422
423try {
424    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
425	    console.info('==========================>getWantAgentCallback=======================>');
426        wantAgent = data;
427    });
428
429    WantAgent.getUid(wantAgent).then((data) => {
430	    console.info('==========================>getUidCallback=======================>');
431    });
432} catch (paramError) {
433    console.log('error: ' + paramError.code + ', ' + paramError.message);
434}
435```
436
437
438
439## WantAgent.getWant
440
441getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void
442
443Obtains the want in a **WantAgent** object. This API uses an asynchronous callback to return the result.
444
445**System capability**: SystemCapability.Ability.AbilityRuntime.Core
446
447**System API**: This is a system API and cannot be called by third-party applications.
448
449**Parameters**
450
451| Name    | Type                 | Mandatory| Description                           |
452| -------- | --------------------- | ---- | ------------------------------- |
453| agent    | WantAgent             | Yes  | Target **WantAgent** object.                  |
454| callback | AsyncCallback\<[Want](js-apis-app-ability-want.md)\> | Yes  | Callback used to return the want.|
455
456**Example**
457
458```js
459import WantAgent from '@ohos.app.ability.wantAgent';
460
461
462// wantAgent object
463let wantAgent;
464
465// getWantAgent callback
466function getWantAgentCallback(err, data) {
467	console.info('==========================>getWantAgentCallback=======================>');
468    if (err.code == 0) {
469    	wantAgent = data;
470    } else {
471        console.info('----getWantAgent failed!----');
472    }
473}
474// WantAgentInfo object
475let wantAgentInfo = {
476    wants: [
477        {
478            deviceId: 'deviceId',
479            bundleName: 'com.neu.setResultOnAbilityResultTest1',
480            abilityName: 'com.example.test.MainAbility',
481            action: 'action1',
482            entities: ['entity1'],
483            type: 'MIMETYPE',
484            uri: 'key={true,true,false}',
485            parameters:
486            {
487                mykey0: 2222,
488                mykey1: [1, 2, 3],
489                mykey2: '[1, 2, 3]',
490                mykey3: 'ssssssssssssssssssssssssss',
491                mykey4: [false, true, false],
492                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
493                mykey6: true,
494            }
495        }
496    ],
497    operationType: WantAgent.OperationType.START_ABILITIES,
498    requestCode: 0,
499    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
500};
501
502try {
503    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
504
505    // getWant callback
506    function getWantCallback(err, data) {
507	    console.info('==========================>getWantCallback=======================>');
508    }
509    WantAgent.getWant(wantAgent, getWantCallback);
510} catch (paramError) {
511    console.log('error: ' + paramError.code + ', ' + paramError.message);
512}
513```
514
515
516
517## WantAgent.getWant
518
519getWant(agent: WantAgent): Promise\<Want\>
520
521Obtains the want in a **WantAgent** object. This API uses a promise to return the result.
522
523**System capability**: SystemCapability.Ability.AbilityRuntime.Core
524
525**System API**: This is a system API and cannot be called by third-party applications.
526
527**Parameters**
528
529| Name | Type     | Mandatory| Description         |
530| ----- | --------- | ---- | ------------- |
531| agent | WantAgent | Yes  | Target **WantAgent** object.|
532
533**Return value**
534
535| Type                                                       | Description                                                        |
536| ----------------------------------------------------------- | ------------------------------------------------------------ |
537| Promise\<Want\> | Promise used to return the want.|
538
539**Example**
540
541```js
542import WantAgent from '@ohos.app.ability.wantAgent';
543
544
545// wantAgent object
546let wantAgent;
547
548// WantAgentInfo object
549let wantAgentInfo = {
550    wants: [
551        {
552            deviceId: 'deviceId',
553            bundleName: 'com.neu.setResultOnAbilityResultTest1',
554            abilityName: 'com.example.test.MainAbility',
555            action: 'action1',
556            entities: ['entity1'],
557            type: 'MIMETYPE',
558            uri: 'key={true,true,false}',
559            parameters:
560            {
561                mykey0: 2222,
562                mykey1: [1, 2, 3],
563                mykey2: '[1, 2, 3]',
564                mykey3: 'ssssssssssssssssssssssssss',
565                mykey4: [false, true, false],
566                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
567                mykey6: true,
568            }
569        }
570    ],
571    operationType: WantAgent.OperationType.START_ABILITIES,
572    requestCode: 0,
573    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
574};
575
576try {
577    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
578	    console.info('==========================>getWantAgentCallback=======================>');
579        wantAgent = data;
580    });
581
582    WantAgent.getWant(wantAgent).then((data) => {
583	    console.info('==========================>getWantCallback=======================>');
584    });
585} catch (paramError) {
586    console.log('error: ' + paramError.code + ', ' + paramError.message);
587}
588```
589
590
591
592## WantAgent.cancel
593
594cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void
595
596Cancels a **WantAgent** object. This API uses an asynchronous callback to return the result.
597
598**System capability**: SystemCapability.Ability.AbilityRuntime.Core
599
600**Parameters**
601
602| Name    | Type                 | Mandatory| Description                       |
603| -------- | --------------------- | ---- | --------------------------- |
604| agent    | WantAgent             | Yes  | Target **WantAgent** object.              |
605| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
606
607**Example**
608
609```js
610import WantAgent from '@ohos.app.ability.wantAgent';
611
612
613// wantAgent object
614let wantAgent;
615
616// getWantAgent callback
617function getWantAgentCallback(err, data) {
618	console.info('==========================>getWantAgentCallback=======================>');
619    if (err.code == 0) {
620    	wantAgent = data;
621    } else {
622        console.info('----getWantAgent failed!----');
623    }
624}
625// WantAgentInfo object
626let wantAgentInfo = {
627    wants: [
628        {
629            deviceId: 'deviceId',
630            bundleName: 'com.neu.setResultOnAbilityResultTest1',
631            abilityName: 'com.example.test.MainAbility',
632            action: 'action1',
633            entities: ['entity1'],
634            type: 'MIMETYPE',
635            uri: 'key={true,true,false}',
636            parameters:
637            {
638                mykey0: 2222,
639                mykey1: [1, 2, 3],
640                mykey2: '[1, 2, 3]',
641                mykey3: 'ssssssssssssssssssssssssss',
642                mykey4: [false, true, false],
643                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
644                mykey6: true,
645            }
646        }
647    ],
648    operationType: WantAgent.OperationType.START_ABILITIES,
649    requestCode: 0,
650    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
651};
652
653try {
654    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
655
656    // cancel callback
657    function cancelCallback(err, data) {
658	    console.info('==========================>cancelCallback=======================>');
659    }
660    WantAgent.cancel(wantAgent, cancelCallback);
661} catch (paramError) {
662    console.log('error: ' + paramError.code + ', ' + paramError.message);
663}
664```
665
666
667
668## WantAgent.cancel
669
670cancel(agent: WantAgent): Promise\<void\>
671
672Cancels a **WantAgent** object. This API uses a promise to return the result.
673
674**System capability**: SystemCapability.Ability.AbilityRuntime.Core
675
676**Parameters**
677
678| Name | Type     | Mandatory| Description         |
679| ----- | --------- | ---- | ------------- |
680| agent | WantAgent | Yes  | Target **WantAgent** object.|
681
682**Return value**
683
684| Type           | Description                           |
685| --------------- | ------------------------------- |
686| Promise\<void\> | Promise used to return the result.|
687
688**Example**
689
690```js
691import WantAgent from '@ohos.app.ability.wantAgent';
692
693
694// wantAgent object
695let wantAgent;
696
697// WantAgentInfo object
698let wantAgentInfo = {
699    wants: [
700        {
701            deviceId: 'deviceId',
702            bundleName: 'com.neu.setResultOnAbilityResultTest1',
703            abilityName: 'com.example.test.MainAbility',
704            action: 'action1',
705            entities: ['entity1'],
706            type: 'MIMETYPE',
707            uri: 'key={true,true,false}',
708            parameters:
709            {
710                mykey0: 2222,
711                mykey1: [1, 2, 3],
712                mykey2: '[1, 2, 3]',
713                mykey3: 'ssssssssssssssssssssssssss',
714                mykey4: [false, true, false],
715                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
716                mykey6: true,
717            }
718        }
719    ],
720    operationType: WantAgent.OperationType.START_ABILITIES,
721    requestCode: 0,
722    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
723};
724
725try {
726    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
727	    console.info('==========================>getWantAgentCallback=======================>');
728        wantAgent = data;
729    });
730
731    WantAgent.cancel(wantAgent).then((data) => {
732	    console.info('==========================>cancelCallback=======================>');
733    });
734} catch (paramError) {
735    console.log('error: ' + paramError.code + ', ' + paramError.message);
736}
737```
738
739
740
741## WantAgent.trigger
742
743trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<CompleteData\>): void
744
745Triggers a **WantAgent** object. This API uses an asynchronous callback to return the result.
746
747**System capability**: SystemCapability.Ability.AbilityRuntime.Core
748
749**Parameters**
750
751| Name       | Type                         | Mandatory| Description                           |
752| ----------- | ----------------------------- | ---- | ------------------------------- |
753| agent       | WantAgent                     | Yes  | Target **WantAgent** object.                  |
754| triggerInfo | TriggerInfo                  | Yes  | **TriggerInfo** object.                |
755| callback    | AsyncCallback\<[CompleteData](#completedata)\> | No  | Callback used to return the result.|
756
757
758```js
759import WantAgent from '@ohos.app.ability.wantAgent';
760
761
762// wantAgent object
763let wantAgent;
764
765// getWantAgent callback
766function getWantAgentCallback(err, data) {
767	console.info('==========================>getWantAgentCallback=======================>');
768    if (err.code == 0) {
769    	wantAgent = data;
770    } else {
771        console.info('----getWantAgent failed!----');
772    }
773}
774// WantAgentInfo object
775let wantAgentInfo = {
776    wants: [
777        {
778            deviceId: 'deviceId',
779            bundleName: 'com.neu.setResultOnAbilityResultTest1',
780            abilityName: 'com.example.test.MainAbility',
781            action: 'action1',
782            entities: ['entity1'],
783            type: 'MIMETYPE',
784            uri: 'key={true,true,false}',
785            parameters:
786            {
787                mykey0: 2222,
788                mykey1: [1, 2, 3],
789                mykey2: '[1, 2, 3]',
790                mykey3: 'ssssssssssssssssssssssssss',
791                mykey4: [false, true, false],
792                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
793                mykey6: true,
794            }
795        }
796    ],
797    operationType: WantAgent.OperationType.START_ABILITIES,
798    requestCode: 0,
799    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
800};
801
802try {
803    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
804
805    // trigger callback
806    function triggerCallback(data) {
807	    console.info('==========================>triggerCallback=======================>');
808    }
809
810
811    let triggerInfo = {
812        code:0
813    };
814    WantAgent.trigger(wantAgent, triggerInfo, triggerCallback);
815} catch (paramError) {
816    console.log('error: ' + paramError.code + ', ' + paramError.message);
817}
818```
819
820
821
822## WantAgent.equal
823
824equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void
825
826Checks 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.
827
828**System capability**: SystemCapability.Ability.AbilityRuntime.Core
829
830**Parameters**
831
832| Name      | Type                    | Mandatory| Description                                   |
833| ---------- | ------------------------ | ---- | --------------------------------------- |
834| agent      | WantAgent                | Yes  | The first **WantAgent** object.                          |
835| otherAgent | WantAgent                | Yes  | The second **WantAgent** object.                          |
836| callback   | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.|
837
838**Example**
839
840```js
841import WantAgent from '@ohos.app.ability.wantAgent';
842
843
844// wantAgent object
845let wantAgent1;
846let wantAgent2;
847
848// getWantAgent callback
849function getWantAgentCallback(err, data) {
850	console.info('==========================>getWantAgentCallback=======================>');
851    if (err.code == 0) {
852    	wantAgent1 = data;
853        wantAgent2 = data;
854    } else {
855        console.info('----getWantAgent failed!----');
856    }
857}
858// WantAgentInfo object
859let wantAgentInfo = {
860    wants: [
861        {
862            deviceId: 'deviceId',
863            bundleName: 'com.neu.setResultOnAbilityResultTest1',
864            abilityName: 'com.example.test.MainAbility',
865            action: 'action1',
866            entities: ['entity1'],
867            type: 'MIMETYPE',
868            uri: 'key={true,true,false}',
869            parameters:
870            {
871                mykey0: 2222,
872                mykey1: [1, 2, 3],
873                mykey2: '[1, 2, 3]',
874                mykey3: 'ssssssssssssssssssssssssss',
875                mykey4: [false, true, false],
876                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
877                mykey6: true,
878            }
879        }
880    ],
881    operationType: WantAgent.OperationType.START_ABILITIES,
882    requestCode: 0,
883    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
884};
885
886try {
887    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
888
889    // equal callback
890    function equalCallback(err, data) {
891	    console.info('==========================>equalCallback=======================>');
892    }
893    WantAgent.equal(wantAgent1, wantAgent2, equalCallback);
894} catch (paramError) {
895    console.log('error: ' + paramError.code + ', ' + paramError.message);
896}
897```
898
899
900
901## WantAgent.equal
902
903equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>
904
905Checks 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.
906
907**System capability**: SystemCapability.Ability.AbilityRuntime.Core
908
909**Parameters**
910
911| Name      | Type     | Mandatory| Description         |
912| ---------- | --------- | ---- | ------------- |
913| agent      | WantAgent | Yes  | The first **WantAgent** object.|
914| otherAgent | WantAgent | Yes  | The second **WantAgent** object.|
915
916**Return value**
917
918| Type                                                       | Description                                                        |
919| ----------------------------------------------------------- | ------------------------------------------------------------ |
920| Promise\<boolean\> | Promise used to return the result.|
921
922**Example**
923
924```js
925import WantAgent from '@ohos.app.ability.wantAgent';
926
927
928// wantAgent object
929let wantAgent1;
930let wantAgent2;
931
932// WantAgentInfo object
933let wantAgentInfo = {
934    wants: [
935        {
936            deviceId: 'deviceId',
937            bundleName: 'com.neu.setResultOnAbilityResultTest1',
938            abilityName: 'com.example.test.MainAbility',
939            action: 'action1',
940            entities: ['entity1'],
941            type: 'MIMETYPE',
942            uri: 'key={true,true,false}',
943            parameters:
944            {
945                mykey0: 2222,
946                mykey1: [1, 2, 3],
947                mykey2: '[1, 2, 3]',
948                mykey3: 'ssssssssssssssssssssssssss',
949                mykey4: [false, true, false],
950                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
951                mykey6: true,
952            }
953        }
954    ],
955    operationType: WantAgent.OperationType.START_ABILITIES,
956    requestCode: 0,
957    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
958};
959
960try {
961    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
962	    console.info('==========================>getWantAgentCallback=======================>');
963        wantAgent1 = data;
964        wantAgent2 = data;
965    });
966
967    WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
968	    console.info('==========================>equalCallback=======================>');
969    });
970} catch (paramError) {
971    console.log('error: ' + paramError.code + ', ' + paramError.message);
972}
973```
974
975## WantAgent.getOperationType
976
977getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void;
978
979Obtains the operation type of a **WantAgent** object. This API uses an asynchronous callback to return the result.
980
981**System capability**: SystemCapability.Ability.AbilityRuntime.Core
982
983**Parameters**
984
985| Name      | Type                    | Mandatory| Description                                   |
986| ---------- | ------------------------ | ---- | --------------------------------------- |
987| agent      | WantAgent                | Yes  | Target **WantAgent** object.                          |
988| callback   | AsyncCallback\<number> | Yes  | Callback used to return the operation type.|
989
990**Example**
991
992```js
993import WantAgent from '@ohos.app.ability.wantAgent';
994
995// wantAgent object
996let wantAgent;
997
998// WantAgentInfo object
999let wantAgentInfo = {
1000    wants: [
1001        {
1002            deviceId: 'deviceId',
1003            bundleName: 'com.neu.setResultOnAbilityResultTest1',
1004            abilityName: 'com.example.test.MainAbility',
1005            action: 'action1',
1006            entities: ['entity1'],
1007            type: 'MIMETYPE',
1008            uri: 'key={true,true,false}',
1009            parameters:
1010            {
1011                mykey0: 2222,
1012                mykey1: [1, 2, 3],
1013                mykey2: '[1, 2, 3]',
1014                mykey3: 'ssssssssssssssssssssssssss',
1015                mykey4: [false, true, false],
1016                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
1017                mykey6: true,
1018            }
1019        }
1020    ],
1021    operationType: WantAgent.OperationType.START_ABILITIES,
1022    requestCode: 0,
1023    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1024};
1025
1026try {
1027    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
1028	    console.info('==========================>getWantAgentCallback=======================>');
1029        wantAgent = data;
1030    });
1031
1032    WantAgent.getOperationType(wantAgent, (OperationType) => {
1033        console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
1034    })
1035} catch (paramError) {
1036    console.log('error: ' + paramError.code + ', ' + paramError.message);
1037}
1038```
1039
1040## WantAgent.getOperationType
1041
1042getOperationType(agent: WantAgent): Promise\<number>;
1043
1044Obtains the operation type of a **WantAgent** object. This API uses a promise to return the result.
1045
1046**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1047
1048**Parameters**
1049
1050| Name      | Type     | Mandatory| Description         |
1051| ---------- | --------- | ---- | ------------- |
1052| agent      | WantAgent | Yes  | Target **WantAgent** object.|
1053
1054**Return value**
1055
1056| Type                                                       | Description                                                        |
1057| ----------------------------------------------------------- | ------------------------------------------------------------ |
1058| Promise\<number> | Promise used to return the operation type.|
1059
1060**Example**
1061
1062```js
1063import WantAgent from '@ohos.app.ability.wantAgent';
1064
1065// wantAgent object
1066let wantAgent;
1067
1068// WantAgentInfo object
1069let wantAgentInfo = {
1070    wants: [
1071        {
1072            deviceId: 'deviceId',
1073            bundleName: 'com.neu.setResultOnAbilityResultTest1',
1074            abilityName: 'com.example.test.MainAbility',
1075            action: 'action1',
1076            entities: ['entity1'],
1077            type: 'MIMETYPE',
1078            uri: 'key={true,true,false}',
1079            parameters:
1080            {
1081                mykey0: 2222,
1082                mykey1: [1, 2, 3],
1083                mykey2: '[1, 2, 3]',
1084                mykey3: 'ssssssssssssssssssssssssss',
1085                mykey4: [false, true, false],
1086                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
1087                mykey6: true,
1088            }
1089        }
1090    ],
1091    operationType: WantAgent.OperationType.START_ABILITIES,
1092    requestCode: 0,
1093    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1094};
1095
1096try {
1097    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
1098	    console.info('==========================>getWantAgentCallback=======================>');
1099        wantAgent = data;
1100    });
1101
1102    WantAgent.getOperationType(wantAgent).then((OperationType) => {
1103        console.log('getOperationType success, OperationType: ' + OperationType);
1104    }).catch((err) => {
1105        console.log('getOperationType fail, err: ' + err);
1106    })
1107} catch (paramError) {
1108    console.log('error: ' + paramError.code + ', ' + paramError.message);
1109}
1110```
1111
1112## WantAgentFlags
1113
1114**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1115
1116| Name               | Value            | Description                                                        |
1117| ------------------- | -------------- | ------------------------------------------------------------ |
1118| ONE_TIME_FLAG       | 0 | The **WantAgent** object can be used only once.                                     |
1119| NO_BUILD_FLAG       | 1 | The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned.     |
1120| CANCEL_PRESENT_FLAG | 2 | The existing **WantAgent** object should be canceled before a new object is generated.|
1121| UPDATE_PRESENT_FLAG | 3 | Extra information of the existing **WantAgent** object is replaced with that of the new object.|
1122| CONSTANT_FLAG       | 4 | The **WantAgent** object is immutable.                                       |
1123| REPLACE_ELEMENT     | 5 | The **element** attribute of the current **Want** can be replaced by the **element** attribute of the **Want** in **WantAgent.trigger()**.|
1124| REPLACE_ACTION      | 6 | The **action** attribute of the current **Want** can be replaced by the **action** attribute of the **Want** in **WantAgent.trigger()**.|
1125| REPLACE_URI         | 7 | The **uri** attribute of the current **Want** can be replaced by the **uri** attribute of the **Want** in **WantAgent.trigger()**.|
1126| REPLACE_ENTITIES    | 8 | The **entities** attribute of the current **Want** can be replaced by the **entities** attribute of the **Want** in **WantAgent.trigger()**.|
1127| REPLACE_BUNDLE      | 9 | The **bundleName** attribute of the current **Want** can be replaced by the **bundleName** attribute of **Want** in **WantAgent.trigger()**.|
1128
1129
1130
1131## OperationType
1132
1133**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1134
1135| Name             | Value           | Description                     |
1136| ----------------- | ------------- | ------------------------- |
1137| UNKNOWN_TYPE      | 0 | Unknown operation type.           |
1138| START_ABILITY     | 1 | Starts an ability with a UI.|
1139| START_ABILITIES   | 2 | Starts multiple abilities with a UI.|
1140| START_SERVICE     | 3 | Starts an ability without a UI.|
1141| SEND_COMMON_EVENT | 4 | Sends a common event.       |
1142
1143
1144
1145## CompleteData
1146
1147**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1148
1149| Name          | Type                          | Mandatory| Description                   |
1150| -------------- | ------------------------------ | ---- | ---------------------- |
1151| info           | WantAgent                       | Yes  | A triggered **WantAgent** object.      |
1152| want           | Want                            | Yes  | An existing triggered **want**.    |
1153| finalCode      | number                          | Yes  | Request code that triggers the **WantAgent** object.|
1154| finalData      | string                          | Yes  | Final data collected by the common event. |
1155| extraInfo      | {[key: string]: any}            | No  | Extra information.              |
1156
1157