• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.wantAgent (WantAgent模块)
2
3WantAgent模块提供了触发、取消、比较WantAgent实例和获取bundle名称的能力,包括创建WantAgent实例、获取实例的用户ID、获取want信息等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```js
12import WantAgent from '@ohos.app.ability.wantAgent';
13```
14
15## WantAgent.getWantAgent
16
17getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void
18
19创建WantAgent(callback形式)。 创建失败返回的WantAgent为空值。
20
21**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
22
23**参数:**
24
25| 参数名     | 类型                       | 必填 | 说明                    |
26| -------- | -------------------------- | ---- | ----------------------- |
27| info     | WantAgentInfo              | 是   | WantAgent信息。           |
28| callback | AsyncCallback\<WantAgent\> | 是   | 创建WantAgent的回调方法。 |
29
30**示例:**
31
32```js
33import WantAgent from '@ohos.app.ability.wantAgent';
34
35//getWantAgent回调
36function getWantAgentCallback(err, data) {
37	console.info('==========================>getWantAgentCallback=======================>');
38}
39//WantAgentInfo对象
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
80创建WantAgent(Promise形式)。 创建失败返回的WantAgent为空值。
81
82**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
83
84**参数:**
85
86| 参数名 | 类型          | 必填 | 说明          |
87| ---- | ------------- | ---- | ------------- |
88| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是   | WantAgent信息。 |
89
90**返回值:**
91
92| 类型                                                        | 说明                                                         |
93| ----------------------------------------------------------- | ------------------------------------------------------------ |
94| Promise\<WantAgent\> | 以Promise形式返回WantAgent。 |
95
96**示例:**
97
98```js
99import WantAgent from '@ohos.app.ability.wantAgent';
100
101
102//WantAgentInfo对象
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
145获取WantAgent实例的包名(callback形式)。
146
147**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
148
149**参数:**
150
151| 参数名     | 类型                    | 必填 | 说明                              |
152| -------- | ----------------------- | ---- | --------------------------------- |
153| agent    | WantAgent               | 是   | WantAgent对象。                     |
154| callback | AsyncCallback\<string\> | 是   | 获取WantAgent实例的包名的回调方法。 |
155
156**示例:**
157
158```js
159import WantAgent from '@ohos.app.ability.wantAgent';
160
161
162//wantAgent对象
163let wantAgent;
164
165//getWantAgent回调
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对象
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回调
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
221获取WantAgent实例的包名(Promise形式)。
222
223**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
224
225**参数:**
226
227| 参数名  | 类型      | 必填 | 说明          |
228| ----- | --------- | ---- | ------------- |
229| agent | WantAgent | 是   | WantAgent对象。 |
230
231**返回值:**
232
233| 类型                                                        | 说明                                                         |
234| ----------------------------------------------------------- | ------------------------------------------------------------ |
235| Promise\<string\> | 以Promise形式返回获取WantAgent实例的包名。 |
236
237**示例:**
238
239```js
240import WantAgent from '@ohos.app.ability.wantAgent';
241
242
243//wantAgent对象
244let wantAgent;
245
246//WantAgentInfo对象
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
294获取WantAgent实例的用户ID(callback形式)。
295
296**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
297
298**参数:**
299
300| 参数名     | 类型                    | 必填 | 说明                                |
301| -------- | ----------------------- | ---- | ----------------------------------- |
302| agent    | WantAgent               | 是   | WantAgent对象。                       |
303| callback | AsyncCallback\<number\> | 是   | 获取WantAgent实例的用户ID的回调方法。 |
304
305**示例:**
306
307```js
308import WantAgent from '@ohos.app.ability.wantAgent';
309
310
311//wantAgent对象
312let wantAgent;
313
314//getWantAgent回调
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对象
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回调
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
370获取WantAgent实例的用户ID(Promise形式)。
371
372**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
373
374**参数:**
375
376| 参数名  | 类型      | 必填 | 说明          |
377| ----- | --------- | ---- | ------------- |
378| agent | WantAgent | 是   | WantAgent对象。 |
379
380**返回值:**
381
382| 类型                                                        | 说明                                                         |
383| ----------------------------------------------------------- | ------------------------------------------------------------ |
384| Promise\<number\> | 以Promise形式返回获取WantAgent实例的用户ID。 |
385
386**示例:**
387
388```js
389import WantAgent from '@ohos.app.ability.wantAgent';
390
391
392//wantAgent对象
393let wantAgent;
394
395//WantAgentInfo对象
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
443获取WantAgent对象的want(callback形式)。
444
445**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
446
447**系统API**: 此接口为系统接口,三方应用不支持调用。
448
449**参数:**
450
451| 参数名     | 类型                  | 必填 | 说明                            |
452| -------- | --------------------- | ---- | ------------------------------- |
453| agent    | WantAgent             | 是   | WantAgent对象。                   |
454| callback | AsyncCallback\<[Want](js-apis-app-ability-want.md)\> | 是   | 获取WantAgent对象want的回调方法。 |
455
456**示例:**
457
458```js
459import WantAgent from '@ohos.app.ability.wantAgent';
460
461
462//wantAgent对象
463let wantAgent;
464
465//getWantAgent回调
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对象
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回调
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
521获取WantAgent对象的want(Promise形式)。
522
523**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
524
525**系统API**: 此接口为系统接口,三方应用不支持调用。
526
527**参数:**
528
529| 参数名  | 类型      | 必填 | 说明          |
530| ----- | --------- | ---- | ------------- |
531| agent | WantAgent | 是   | WantAgent对象。 |
532
533**返回值:**
534
535| 类型                                                        | 说明                                                         |
536| ----------------------------------------------------------- | ------------------------------------------------------------ |
537| Promise\<Want\> | 以Promise形式返回获取WantAgent对象的want。 |
538
539**示例:**
540
541```js
542import WantAgent from '@ohos.app.ability.wantAgent';
543
544
545//wantAgent对象
546let wantAgent;
547
548//WantAgentInfo对象
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
596取消WantAgent实例(callback形式)。
597
598**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
599
600**参数:**
601
602| 参数名     | 类型                  | 必填 | 说明                        |
603| -------- | --------------------- | ---- | --------------------------- |
604| agent    | WantAgent             | 是   | WantAgent对象。               |
605| callback | AsyncCallback\<void\> | 是   | 取消WantAgent实例的回调方法。 |
606
607**示例:**
608
609```js
610import WantAgent from '@ohos.app.ability.wantAgent';
611
612
613//wantAgent对象
614let wantAgent;
615
616//getWantAgent回调
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对象
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回调
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
672取消WantAgent实例(Promise形式)。
673
674**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
675
676**参数:**
677
678| 参数名  | 类型      | 必填 | 说明          |
679| ----- | --------- | ---- | ------------- |
680| agent | WantAgent | 是   | WantAgent对象。 |
681
682**返回值:**
683
684| 类型            | 说明                            |
685| --------------- | ------------------------------- |
686| Promise\<void\> | 以Promise形式获取异步返回结果。 |
687
688**示例:**
689
690```js
691import WantAgent from '@ohos.app.ability.wantAgent';
692
693
694//wantAgent对象
695let wantAgent;
696
697//WantAgentInfo对象
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
745主动激发WantAgent实例(callback形式)。
746
747**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
748
749**参数:**
750
751| 参数名        | 类型                          | 必填 | 说明                            |
752| ----------- | ----------------------------- | ---- | ------------------------------- |
753| agent       | WantAgent                     | 是   | WantAgent对象。                   |
754| triggerInfo | TriggerInfo                   | 是   | TriggerInfo对象。                 |
755| callback    | AsyncCallback\<[CompleteData](#completedata)\> | 否   | 主动激发WantAgent实例的回调方法。 |
756
757**示例:**
758
759```js
760import WantAgent from '@ohos.app.ability.wantAgent';
761
762
763//wantAgent对象
764let wantAgent;
765
766//getWantAgent回调
767function getWantAgentCallback(err, data) {
768	console.info('==========================>getWantAgentCallback=======================>');
769    if (err.code == 0) {
770    	wantAgent = data;
771    } else {
772        console.info('----getWantAgent failed!----');
773    }
774}
775//WantAgentInfo对象
776let wantAgentInfo = {
777    wants: [
778        {
779            deviceId: 'deviceId',
780            bundleName: 'com.neu.setResultOnAbilityResultTest1',
781            abilityName: 'com.example.test.MainAbility',
782            action: 'action1',
783            entities: ['entity1'],
784            type: 'MIMETYPE',
785            uri: 'key={true,true,false}',
786            parameters:
787            {
788                mykey0: 2222,
789                mykey1: [1, 2, 3],
790                mykey2: '[1, 2, 3]',
791                mykey3: 'ssssssssssssssssssssssssss',
792                mykey4: [false, true, false],
793                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
794                mykey6: true,
795            }
796        }
797    ],
798    operationType: WantAgent.OperationType.START_ABILITIES,
799    requestCode: 0,
800    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
801};
802
803try {
804    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
805
806    //trigger回调
807    function triggerCallback(data) {
808	    console.info('==========================>triggerCallback=======================>');
809    }
810
811
812    let triggerInfo = {
813        code:0
814    };
815    WantAgent.trigger(wantAgent, triggerInfo, triggerCallback);
816} catch (paramError) {
817    console.log('error: ' + paramError.code + ', ' + paramError.message);
818}
819```
820
821
822
823## WantAgent.equal
824
825equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void
826
827判断两个WantAgent实例是否相等(callback形式)。
828
829**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
830
831**参数:**
832
833| 参数名       | 类型                     | 必填 | 说明                                    |
834| ---------- | ------------------------ | ---- | --------------------------------------- |
835| agent      | WantAgent                | 是   | WantAgent对象。                           |
836| otherAgent | WantAgent                | 是   | WantAgent对象。                           |
837| callback   | AsyncCallback\<boolean\> | 是   | 判断两个WantAgent实例是否相等的回调方法。 |
838
839**示例:**
840
841```js
842import WantAgent from '@ohos.app.ability.wantAgent';
843
844
845//wantAgent对象
846let wantAgent1;
847let wantAgent2;
848
849//getWantAgent回调
850function getWantAgentCallback(err, data) {
851	console.info('==========================>getWantAgentCallback=======================>');
852    if (err.code == 0) {
853    	wantAgent1 = data;
854        wantAgent2 = data;
855    } else {
856        console.info('----getWantAgent failed!----');
857    }
858}
859//WantAgentInfo对象
860let wantAgentInfo = {
861    wants: [
862        {
863            deviceId: 'deviceId',
864            bundleName: 'com.neu.setResultOnAbilityResultTest1',
865            abilityName: 'com.example.test.MainAbility',
866            action: 'action1',
867            entities: ['entity1'],
868            type: 'MIMETYPE',
869            uri: 'key={true,true,false}',
870            parameters:
871            {
872                mykey0: 2222,
873                mykey1: [1, 2, 3],
874                mykey2: '[1, 2, 3]',
875                mykey3: 'ssssssssssssssssssssssssss',
876                mykey4: [false, true, false],
877                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
878                mykey6: true,
879            }
880        }
881    ],
882    operationType: WantAgent.OperationType.START_ABILITIES,
883    requestCode: 0,
884    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
885};
886
887try {
888    WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
889
890    //equal回调
891    function equalCallback(err, data) {
892	    console.info('==========================>equalCallback=======================>');
893    }
894    WantAgent.equal(wantAgent1, wantAgent2, equalCallback);
895} catch (paramError) {
896    console.log('error: ' + paramError.code + ', ' + paramError.message);
897}
898```
899
900
901
902## WantAgent.equal
903
904equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>
905
906判断两个WantAgent实例是否相等(Promise形式)。
907
908**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
909
910**参数:**
911
912| 参数名       | 类型      | 必填 | 说明          |
913| ---------- | --------- | ---- | ------------- |
914| agent      | WantAgent | 是   | WantAgent对象。 |
915| otherAgent | WantAgent | 是   | WantAgent对象。 |
916
917**返回值:**
918
919| 类型                                                        | 说明                                                         |
920| ----------------------------------------------------------- | ------------------------------------------------------------ |
921| Promise\<boolean\> | 以Promise形式返回获取判断两个WantAgent实例是否相等的结果。 |
922
923**示例:**
924
925```js
926import WantAgent from '@ohos.app.ability.wantAgent';
927
928
929//wantAgent对象
930let wantAgent1;
931let wantAgent2;
932
933//WantAgentInfo对象
934let wantAgentInfo = {
935    wants: [
936        {
937            deviceId: 'deviceId',
938            bundleName: 'com.neu.setResultOnAbilityResultTest1',
939            abilityName: 'com.example.test.MainAbility',
940            action: 'action1',
941            entities: ['entity1'],
942            type: 'MIMETYPE',
943            uri: 'key={true,true,false}',
944            parameters:
945            {
946                mykey0: 2222,
947                mykey1: [1, 2, 3],
948                mykey2: '[1, 2, 3]',
949                mykey3: 'ssssssssssssssssssssssssss',
950                mykey4: [false, true, false],
951                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
952                mykey6: true,
953            }
954        }
955    ],
956    operationType: WantAgent.OperationType.START_ABILITIES,
957    requestCode: 0,
958    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
959};
960
961try {
962    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
963	    console.info('==========================>getWantAgentCallback=======================>');
964        wantAgent1 = data;
965        wantAgent2 = data;
966    });
967
968    WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
969	    console.info('==========================>equalCallback=======================>');
970    });
971} catch (paramError) {
972    console.log('error: ' + paramError.code + ', ' + paramError.message);
973}
974```
975
976## WantAgent.getOperationType
977
978getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void;
979
980获取一个WantAgent的OperationType信息(callback形式)。
981
982**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
983
984**参数:**
985
986| 参数名       | 类型                     | 必填 | 说明                                    |
987| ---------- | ------------------------ | ---- | --------------------------------------- |
988| agent      | WantAgent                | 是   | WantAgent对象。                           |
989| callback   | AsyncCallback\<number> | 是   | 获取一个WantAgent的OperationType信息的回调方法。 |
990
991**示例:**
992
993```js
994import WantAgent from '@ohos.app.ability.wantAgent';
995
996//wantAgent对象
997let wantAgent;
998
999//WantAgentInfo对象
1000let wantAgentInfo = {
1001    wants: [
1002        {
1003            deviceId: 'deviceId',
1004            bundleName: 'com.neu.setResultOnAbilityResultTest1',
1005            abilityName: 'com.example.test.MainAbility',
1006            action: 'action1',
1007            entities: ['entity1'],
1008            type: 'MIMETYPE',
1009            uri: 'key={true,true,false}',
1010            parameters:
1011            {
1012                mykey0: 2222,
1013                mykey1: [1, 2, 3],
1014                mykey2: '[1, 2, 3]',
1015                mykey3: 'ssssssssssssssssssssssssss',
1016                mykey4: [false, true, false],
1017                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
1018                mykey6: true,
1019            }
1020        }
1021    ],
1022    operationType: WantAgent.OperationType.START_ABILITIES,
1023    requestCode: 0,
1024    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1025};
1026
1027try {
1028    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
1029	    console.info('==========================>getWantAgentCallback=======================>');
1030        wantAgent = data;
1031    });
1032
1033    WantAgent.getOperationType(wantAgent, (OperationType) => {
1034        console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
1035    })
1036} catch (paramError) {
1037    console.log('error: ' + paramError.code + ', ' + paramError.message);
1038}
1039```
1040
1041## WantAgent.getOperationType
1042
1043getOperationType(agent: WantAgent): Promise\<number>;
1044
1045获取一个WantAgent的OperationType信息(Promise形式)。
1046
1047**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1048
1049**参数:**
1050
1051| 参数名       | 类型      | 必填 | 说明          |
1052| ---------- | --------- | ---- | ------------- |
1053| agent      | WantAgent | 是   | WantAgent对象。 |
1054
1055**返回值:**
1056
1057| 类型                                                        | 说明                                                         |
1058| ----------------------------------------------------------- | ------------------------------------------------------------ |
1059| Promise\<number> | 以Promise形式返回获取operationType的结果。 |
1060
1061**示例:**
1062
1063```js
1064import WantAgent from '@ohos.app.ability.wantAgent';
1065
1066//wantAgent对象
1067let wantAgent;
1068
1069//WantAgentInfo对象
1070let wantAgentInfo = {
1071    wants: [
1072        {
1073            deviceId: 'deviceId',
1074            bundleName: 'com.neu.setResultOnAbilityResultTest1',
1075            abilityName: 'com.example.test.MainAbility',
1076            action: 'action1',
1077            entities: ['entity1'],
1078            type: 'MIMETYPE',
1079            uri: 'key={true,true,false}',
1080            parameters:
1081            {
1082                mykey0: 2222,
1083                mykey1: [1, 2, 3],
1084                mykey2: '[1, 2, 3]',
1085                mykey3: 'ssssssssssssssssssssssssss',
1086                mykey4: [false, true, false],
1087                mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
1088                mykey6: true,
1089            }
1090        }
1091    ],
1092    operationType: WantAgent.OperationType.START_ABILITIES,
1093    requestCode: 0,
1094    wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1095};
1096
1097try {
1098    WantAgent.getWantAgent(wantAgentInfo).then((data) => {
1099	    console.info('==========================>getWantAgentCallback=======================>');
1100        wantAgent = data;
1101    });
1102
1103    WantAgent.getOperationType(wantAgent).then((OperationType) => {
1104        console.log('getOperationType success, OperationType: ' + OperationType);
1105    }).catch((err) => {
1106        console.log('getOperationType fail, err: ' + err);
1107    })
1108} catch (paramError) {
1109    console.log('error: ' + paramError.code + ', ' + paramError.message);
1110}
1111```
1112
1113## WantAgentFlags
1114
1115**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
1116
1117| 名称                | 值             | 说明                                                         |
1118| ------------------- | -------------- | ------------------------------------------------------------ |
1119| ONE_TIME_FLAG       | 0 | WantAgent仅能使用一次。                                      |
1120| NO_BUILD_FLAG       | 1 | 如果描述WantAgent对象不存在,则不创建它,直接返回null。      |
1121| CANCEL_PRESENT_FLAG | 2 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。 |
1122| UPDATE_PRESENT_FLAG | 3 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。 |
1123| CONSTANT_FLAG       | 4 | WantAgent是不可变的。                                        |
1124| REPLACE_ELEMENT     | 5 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代 |
1125| REPLACE_ACTION      | 6 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代 |
1126| REPLACE_URI         | 7 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代 |
1127| REPLACE_ENTITIES    | 8 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代 |
1128| REPLACE_BUNDLE      | 9 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代 |
1129
1130
1131
1132## OperationType
1133
1134**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
1135
1136| 名称              | 值            | 说明                      |
1137| ----------------- | ------------- | ------------------------- |
1138| UNKNOWN_TYPE      | 0 | 不识别的类型。            |
1139| START_ABILITY     | 1 | 开启一个有页面的Ability。 |
1140| START_ABILITIES   | 2 | 开启多个有页面的Ability。 |
1141| START_SERVICE     | 3 | 开启一个无页面的ability。 |
1142| SEND_COMMON_EVENT | 4 | 发送一个公共事件。        |
1143
1144
1145
1146## CompleteData
1147
1148**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
1149
1150| 名称           | 类型                           | 必填 | 说明                    |
1151| -------------- | ------------------------------ | ---- | ---------------------- |
1152| info           | WantAgent                       | 是   | 触发的wantAgent。       |
1153| want           | Want                            | 是   | 存在的被触发的want。     |
1154| finalCode      | number                          | 是   | 触发wantAgent的请求代码。|
1155| finalData      | string                          | 是   | 公共事件收集的最终数据。  |
1156| extraInfo      | {[key: string]: any}            | 否   | 额外数据。               |
1157
1158