• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.wantAgent (WantAgent模块)
2
3WantAgent模块是一个封装了[Want](./js-apis-app-ability-want.md)对象的类,允许应用程序在未来的某个时间点执行该Want。
4
5该模块提供了创建WantAgent实例、获取WantAgent实例所属应用的包名、获取WantAgent实例所属应用的UID、主动激发WantAgent实例、判断两个WantAgent实例是否相等等功能。WantAgent的一个典型应用场景是通知处理。例如,当用户点击通知时,会触发WantAgent的[trigger](#wantagenttrigger)接口,并拉起目标应用。具体使用请参考[通知模块](../../notification/notification-with-wantagent.md)。
6
7> **说明:**
8>
9> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10
11## 导入模块
12
13```ts
14import { wantAgent } from '@kit.AbilityKit';
15```
16
17## wantAgent.getWantAgent
18
19getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void
20
21创建WantAgent,使用callback异步回调。创建成功返回WantAgent对象,创建失败返回空值。
22
23**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
24
25**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
26
27**参数:**
28
29| 参数名     | 类型                       | 必填 | 说明                    |
30| -------- | -------------------------- | ---- | ----------------------- |
31| info     | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md)              | 是   | 表示创建WantAgent所需的配置信息,包括目标UIAbility、操作类型、请求码等。三方应用在WantAgentInfo中只能设置本应用的UIAbility。|
32| callback | AsyncCallback\<WantAgent\> | 是   | 创建WantAgent的回调方法。 |
33
34**错误码:**
35
36以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
37
38| 错误码ID    | 错误信息            |
39|-----------|--------------------|
40| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
41| 16000007   | Service busy. There are concurrent tasks. Try again later. |
42| 16000151   | Invalid wantAgent object.|
43
44**示例:**
45
46```ts
47import { wantAgent, Want } from '@kit.AbilityKit';
48import type { WantAgent } from '@kit.AbilityKit';
49import { BusinessError } from '@kit.BasicServicesKit';
50
51//wantAgent对象
52let wantAgentData: WantAgent;
53//WantAgentInfo对象
54let wantAgentInfo: wantAgent.WantAgentInfo = {
55  wants: [
56    {
57      deviceId: 'deviceId',
58      bundleName: 'com.example.myapplication',
59      abilityName: 'EntryAbility',
60      action: 'action1',
61      entities: ['entity1'],
62      type: 'MIMETYPE',
63      uri: 'key={true,true,false}',
64      parameters:
65      {
66        mykey0: 2222,
67        mykey1: [1, 2, 3],
68        mykey2: '[1, 2, 3]',
69        mykey3: 'ssssssssssssssssssssssssss',
70        mykey4: [false, true, false],
71        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
72        mykey6: true,
73      }
74    } as Want
75  ],
76  actionType: wantAgent.OperationType.START_ABILITY,
77  requestCode: 0,
78  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
79};
80
81//getWantAgent回调
82function getWantAgentCallback(err: BusinessError, data: WantAgent) {
83  if (err) {
84    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
85  } else {
86    wantAgentData = data;
87  }
88}
89
90try {
91  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
92} catch (err) {
93  console.error(`getWantAgent failed, error: ${JSON.stringify(err)}`);
94}
95```
96
97## wantAgent.getWantAgent
98
99getWantAgent(info: WantAgentInfo): Promise\<WantAgent\>
100
101创建WantAgent,使用Promise异步回调。 创建成功返回WantAgent对象,创建失败返回空值。
102
103**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
104
105**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
106
107**参数:**
108
109| 参数名 | 类型          | 必填 | 说明          |
110| ---- | ------------- | ---- | ------------- |
111| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是   | 表示创建WantAgent所需的配置信息,包括目标UIAbility、操作类型、请求码等。三方应用在WantAgentInfo中只能设置本应用的UIAbility。|
112
113**返回值:**
114
115| 类型                                                        | 说明                                                         |
116| ----------------------------------------------------------- | ------------------------------------------------------------ |
117| Promise\<WantAgent\> | 以Promise形式返回WantAgent。 |
118
119**错误码:**
120
121以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
122
123| 错误码ID    | 错误信息            |
124|-----------|--------------------|
125| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
126| 16000007   | Service busy. There are concurrent tasks. Try again later. |
127| 16000151   | Invalid wantAgent object.|
128
129**示例:**
130
131```ts
132import { wantAgent, Want } from '@kit.AbilityKit';
133import type { WantAgent } from '@kit.AbilityKit';
134import { BusinessError } from '@kit.BasicServicesKit';
135
136let wantAgentData: WantAgent;
137//WantAgentInfo对象
138let wantAgentInfo: wantAgent.WantAgentInfo = {
139  wants: [
140    {
141      deviceId: 'deviceId',
142      bundleName: 'com.example.myapplication',
143      abilityName: 'EntryAbility',
144      action: 'action1',
145      entities: ['entity1'],
146      type: 'MIMETYPE',
147      uri: 'key={true,true,false}',
148      parameters:
149      {
150        mykey0: 2222,
151        mykey1: [1, 2, 3],
152        mykey2: '[1, 2, 3]',
153        mykey3: 'ssssssssssssssssssssssssss',
154        mykey4: [false, true, false],
155        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
156        mykey6: true,
157      }
158    } as Want
159  ],
160  actionType: wantAgent.OperationType.START_ABILITY,
161  requestCode: 0,
162  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
163};
164
165try {
166  wantAgent.getWantAgent(wantAgentInfo).then((data) => {
167    wantAgentData = data;
168  }).catch((err: BusinessError) => {
169    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
170  });
171} catch (err) {
172  console.error(`getWantAgent failed! ${err.code} ${err.message}`);
173}
174```
175
176
177
178## wantAgent.getBundleName
179
180getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void
181
182获取WantAgent实例所属应用的包名,使用callback异步回调。
183
184**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
185
186**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
187
188**参数:**
189
190| 参数名     | 类型                    | 必填 | 说明                              |
191| -------- | ----------------------- | ---- | --------------------------------- |
192| agent    | WantAgent               | 是   | WantAgent对象。                     |
193| callback | AsyncCallback\<string\> | 是   | 获取WantAgent实例的包名的回调方法。 |
194
195**错误码:**
196
197以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
198
199| 错误码ID    | 错误信息            |
200|-----------|--------------------|
201| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
202| 16000007   | Service busy. There are concurrent tasks. Try again later. |
203| 16000151   | Invalid wantAgent object.|
204
205**示例:**
206
207```ts
208import { wantAgent, Want } from '@kit.AbilityKit';
209import type { WantAgent } from '@kit.AbilityKit';
210import { BusinessError } from '@kit.BasicServicesKit';
211
212//wantAgent对象
213let wantAgentData: WantAgent;
214//WantAgentInfo对象
215let wantAgentInfo: wantAgent.WantAgentInfo = {
216  wants: [
217    {
218      deviceId: 'deviceId',
219      bundleName: 'com.example.myapplication',
220      abilityName: 'EntryAbility',
221      action: 'action1',
222      entities: ['entity1'],
223      type: 'MIMETYPE',
224      uri: 'key={true,true,false}',
225      parameters:
226      {
227        mykey0: 2222,
228        mykey1: [1, 2, 3],
229        mykey2: '[1, 2, 3]',
230        mykey3: 'ssssssssssssssssssssssssss',
231        mykey4: [false, true, false],
232        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
233        mykey6: true,
234      }
235    } as Want
236  ],
237  actionType: wantAgent.OperationType.START_ABILITY,
238  requestCode: 0,
239  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
240};
241
242//getWantAgent回调
243function getWantAgentCallback(err: BusinessError, data: WantAgent) {
244  if (err) {
245    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
246  } else {
247    wantAgentData = data;
248  }
249  //getBundleName回调
250  let getBundleNameCallback = (err: BusinessError, data: string) => {
251    if (err) {
252      console.error(`getBundleName failed! ${err.code} ${err.message}`);
253    } else {
254      console.info(`getBundleName ok! ${JSON.stringify(data)}`);
255    }
256  }
257  try {
258    wantAgent.getBundleName(wantAgentData, getBundleNameCallback);
259  } catch (err) {
260    console.error(`getBundleName failed! ${err.code} ${err.message}`);
261  }
262}
263
264try {
265  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
266} catch (err) {
267  console.error(`getWantAgent failed! ${err.code} ${err.message}`);
268}
269```
270
271## wantAgent.getBundleName
272
273getBundleName(agent: WantAgent): Promise\<string\>
274
275获取WantAgent实例所属应用的包名,使用Promise异步回调。
276
277**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
278
279**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
280
281**参数:**
282
283| 参数名  | 类型      | 必填 | 说明          |
284| ----- | --------- | ---- | ------------- |
285| agent | WantAgent | 是   | WantAgent对象。 |
286
287**返回值:**
288
289| 类型                                                        | 说明                                                         |
290| ----------------------------------------------------------- | ------------------------------------------------------------ |
291| Promise\<string\> | 以Promise形式返回获取WantAgent实例的包名。 |
292
293**错误码:**
294
295以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
296
297| 错误码ID    | 错误信息            |
298|-----------|--------------------|
299| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
300| 16000007   | Service busy. There are concurrent tasks. Try again later. |
301| 16000151   | Invalid wantAgent object.|
302
303**示例:**
304
305```ts
306import { wantAgent, Want } from '@kit.AbilityKit';
307import type { WantAgent } from '@kit.AbilityKit';
308import { BusinessError } from '@kit.BasicServicesKit';
309
310//wantAgent对象
311let wantAgentData: WantAgent;
312//WantAgentInfo对象
313let wantAgentInfo: wantAgent.WantAgentInfo = {
314  wants: [
315    {
316      deviceId: 'deviceId',
317      bundleName: 'com.example.myapplication',
318      abilityName: 'EntryAbility',
319      action: 'action1',
320      entities: ['entity1'],
321      type: 'MIMETYPE',
322      uri: 'key={true,true,false}',
323      parameters:
324      {
325        mykey0: 2222,
326        mykey1: [1, 2, 3],
327        mykey2: '[1, 2, 3]',
328        mykey3: 'ssssssssssssssssssssssssss',
329        mykey4: [false, true, false],
330        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
331        mykey6: true,
332      }
333    } as Want
334  ],
335  actionType: wantAgent.OperationType.START_ABILITY,
336  requestCode: 0,
337  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
338};
339
340//getWantAgent回调
341function getWantAgentCallback(err: BusinessError, data: WantAgent) {
342  if (err) {
343    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
344  } else {
345    wantAgentData = data;
346  }
347  try {
348    wantAgent.getBundleName(wantAgentData).then((data)=>{
349      console.info(`getBundleName ok! ${JSON.stringify(data)}`);
350    }).catch((err: BusinessError)=>{
351      console.error(`getBundleName failed! ${err.code} ${err.message}`);
352    });
353  } catch(err){
354    console.error(`getBundleName failed! ${err.code} ${err.message}`);
355  }
356}
357try {
358  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
359} catch(err) {
360  console.error(`getWantAgent failed! ${err.code} ${err.message}`);
361}
362```
363
364## wantAgent.getUid
365
366getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void
367
368获取WantAgent实例所属应用的UID,使用callback异步回调。
369
370**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
371
372**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
373
374**参数:**
375
376| 参数名     | 类型                    | 必填 | 说明                                |
377| -------- | ----------------------- | ---- | ----------------------------------- |
378| agent    | WantAgent               | 是   | WantAgent对象。                       |
379| callback | AsyncCallback\<number\> | 是   | 获取WantAgent实例所属应用的UID的回调方法。 |
380
381**错误码:**
382
383以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
384
385| 错误码ID    | 错误信息            |
386|-----------|--------------------|
387| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
388| 16000007   | Service busy. There are concurrent tasks. Try again later. |
389| 16000151   | Invalid wantAgent object.|
390
391**示例:**
392
393```ts
394import { wantAgent, Want } from '@kit.AbilityKit';
395import type { WantAgent } from '@kit.AbilityKit';
396import { BusinessError } from '@kit.BasicServicesKit';
397
398//wantAgent对象
399let wantAgentData: WantAgent;
400//WantAgentInfo对象
401let wantAgentInfo: wantAgent.WantAgentInfo = {
402  wants: [
403    {
404      deviceId: 'deviceId',
405      bundleName: 'com.example.myapplication',
406      abilityName: 'EntryAbility',
407      action: 'action1',
408      entities: ['entity1'],
409      type: 'MIMETYPE',
410      uri: 'key={true,true,false}',
411      parameters:
412      {
413        mykey0: 2222,
414        mykey1: [1, 2, 3],
415        mykey2: '[1, 2, 3]',
416        mykey3: 'ssssssssssssssssssssssssss',
417        mykey4: [false, true, false],
418        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
419        mykey6: true,
420      }
421    } as Want
422  ],
423  actionType: wantAgent.OperationType.START_ABILITY,
424  requestCode: 0,
425  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
426};
427
428//getWantAgent回调
429function getWantAgentCallback(err: BusinessError, data: WantAgent) {
430  if (err) {
431    console.error(`getWantAgent failed, code: ${err.code}, message: ${err.message}.`);
432  } else {
433    wantAgentData = data;
434  }
435  //getUid回调
436  let getUidCallback = (err: BusinessError, data: number) => {
437    if (err) {
438      console.error(`getUid failed, err code: ${err.code}, err msg: ${err.message}.`);
439    } else {
440      console.info(`getUid ok, data: ${JSON.stringify(data)}.`);
441    }
442  }
443  try {
444    wantAgent.getUid(wantAgentData, getUidCallback);
445  } catch (err) {
446    let code = (err as BusinessError).code;
447    let msg = (err as BusinessError).message;
448    console.error(`getUid failed, err code: ${code}, err msg: ${msg}.`);
449  }
450}
451
452try {
453  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
454} catch (err) {
455  let code = (err as BusinessError).code;
456  let msg = (err as BusinessError).message;
457  console.error(`getWantAgent failed, err code: ${code}, err msg: ${msg}.`);
458}
459```
460
461## wantAgent.getUid
462
463getUid(agent: WantAgent): Promise\<number\>
464
465获取WantAgent实例所属应用的UID,使用Promise异步回调。
466
467**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
468
469**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
470
471**参数:**
472
473| 参数名  | 类型      | 必填 | 说明          |
474| ----- | --------- | ---- | ------------- |
475| agent | WantAgent | 是   | WantAgent对象。 |
476
477**返回值:**
478
479| 类型              | 说明                                              |
480| ----------------- | ------------------------------------------------- |
481| Promise\<number\> | 以Promise形式返回获取WantAgent实例所属应用的UID。 |
482
483**错误码:**
484
485以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
486
487| 错误码ID    | 错误信息            |
488|-----------|--------------------|
489| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
490| 16000007   | Service busy. There are concurrent tasks. Try again later. |
491| 16000151   | Invalid wantAgent object.|
492
493**示例:**
494
495```ts
496import { wantAgent, Want } from '@kit.AbilityKit';
497import type { WantAgent } from '@kit.AbilityKit';
498import { BusinessError } from '@kit.BasicServicesKit';
499
500//wantAgent对象
501let wantAgentData: WantAgent;
502//WantAgentInfo对象
503let wantAgentInfo: wantAgent.WantAgentInfo = {
504  wants: [
505    {
506      deviceId: 'deviceId',
507      bundleName: 'com.example.myapplication',
508      abilityName: '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    } as Want
524  ],
525  actionType: wantAgent.OperationType.START_ABILITY,
526  requestCode: 0,
527  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
528};
529
530//getWantAgent回调
531function getWantAgentCallback(err: BusinessError, data: WantAgent) {
532  if (err) {
533    console.error(`getWantAgent failed, err code: ${err.code}, err msg: ${err.message}.`);
534  } else {
535    wantAgentData = data;
536  }
537  try {
538    wantAgent.getUid(wantAgentData).then((data) => {
539      console.info(`getUid ok, data: ${JSON.stringify(data)}.`);
540    }).catch((err: BusinessError) => {
541      console.error(`getUid failed, err code: ${err.code}, err msg: ${err.message}.`);
542    });
543  } catch (err) {
544    let code = (err as BusinessError).code;
545    let msg = (err as BusinessError).message;
546    console.error(`getUid failed, err code: ${code}, err msg: ${msg}.`);
547  }
548}
549
550try {
551  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
552} catch (err) {
553  let code = (err as BusinessError).code;
554  let msg = (err as BusinessError).message;
555  console.error(`getWantAgent failed, err code: ${code}, err msg: ${msg}.`);
556}
557```
558
559## wantAgent.cancel
560
561cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void
562
563取消WantAgent实例,使用callback异步回调。
564
565**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
566
567**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
568
569**参数:**
570
571| 参数名     | 类型                  | 必填 | 说明                        |
572| -------- | --------------------- | ---- | --------------------------- |
573| agent    | WantAgent             | 是   | WantAgent对象。               |
574| callback | AsyncCallback\<void\> | 是   | 取消WantAgent实例的回调方法。 |
575
576**错误码:**
577
578以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
579
580| 错误码ID    | 错误信息            |
581|-----------|--------------------|
582| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
583| 16000007   | Service busy. There are concurrent tasks. Try again later. |
584| 16000151   | Invalid wantAgent object.|
585
586**示例:**
587
588```ts
589import { wantAgent, Want } from '@kit.AbilityKit';
590import type { WantAgent } from '@kit.AbilityKit';
591import { BusinessError } from '@kit.BasicServicesKit';
592
593//wantAgent对象
594let wantAgentData: WantAgent;
595//WantAgentInfo对象
596let wantAgentInfo: wantAgent.WantAgentInfo = {
597  wants: [
598    {
599      deviceId: 'deviceId',
600      bundleName: 'com.example.myapplication',
601      abilityName: 'EntryAbility',
602      action: 'action1',
603      entities: ['entity1'],
604      type: 'MIMETYPE',
605      uri: 'key={true,true,false}',
606      parameters:
607      {
608        mykey0: 2222,
609        mykey1: [1, 2, 3],
610        mykey2: '[1, 2, 3]',
611        mykey3: 'ssssssssssssssssssssssssss',
612        mykey4: [false, true, false],
613        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
614        mykey6: true,
615      }
616    } as Want
617  ],
618  actionType: wantAgent.OperationType.START_ABILITY,
619  requestCode: 0,
620  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
621};
622
623//getWantAgent回调
624function getWantAgentCallback(err: BusinessError, data: WantAgent) {
625  if (err) {
626    console.error(`getWantAgent failed, err code: ${err.code}, err msg: ${err.message}.`);
627  } else {
628    wantAgentData = data;
629  }
630  //cancel回调
631  let cancelCallback = (err: BusinessError, data: void) => {
632    if (err) {
633      console.error(`cancel failed, err code: ${err.code}, err msg: ${err.message}.`);
634    } else {
635      console.info(`cancel sucecss.`);
636    }
637  }
638  try {
639    wantAgent.cancel(wantAgentData, cancelCallback);
640  } catch (err) {
641    let code = (err as BusinessError).code;
642    let msg = (err as BusinessError).message;
643    console.error(`cancel failed, err code: ${code}, err msg: ${msg}.`);
644  }
645}
646
647try {
648  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
649} catch (err) {
650  let code = (err as BusinessError).code;
651  let msg = (err as BusinessError).message;
652  console.error(`getWantAgent failed, err code: ${code}, err msg: ${msg}.`);
653}
654```
655
656## wantAgent.cancel
657
658cancel(agent: WantAgent): Promise\<void\>
659
660取消WantAgent实例,使用Promise异步回调。
661
662**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
663
664**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
665
666**参数:**
667
668| 参数名  | 类型      | 必填 | 说明          |
669| ----- | --------- | ---- | ------------- |
670| agent | WantAgent | 是   | WantAgent对象。 |
671
672**返回值:**
673
674| 类型            | 说明                            |
675| --------------- | ------------------------------- |
676| Promise\<void\> | 以Promise形式获取异步返回结果。 |
677
678**错误码:**
679
680以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
681
682| 错误码ID    | 错误信息            |
683|-----------|--------------------|
684| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
685| 16000007   | Service busy. There are concurrent tasks. Try again later. |
686| 16000151   | Invalid wantAgent object.|
687
688**示例:**
689
690```ts
691import { wantAgent, Want } from '@kit.AbilityKit';
692import type { WantAgent } from '@kit.AbilityKit';
693import { BusinessError } from '@kit.BasicServicesKit';
694
695//wantAgent对象
696let wantAgentData: WantAgent;
697//WantAgentInfo对象
698let wantAgentInfo: wantAgent.WantAgentInfo = {
699  wants: [
700    {
701      deviceId: 'deviceId',
702      bundleName: 'com.example.myapplication',
703      abilityName: 'EntryAbility',
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    } as Want
719  ],
720  actionType: wantAgent.OperationType.START_ABILITY,
721  requestCode: 0,
722  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
723};
724
725//getWantAgent回调
726function getWantAgentCallback(err: BusinessError, data: WantAgent) {
727  if (err) {
728    console.error(`getWantAgent failed, err code: ${err.code}, err msg: ${err.message}.`);
729  } else {
730    wantAgentData = data;
731  }
732  try {
733    wantAgent.cancel(wantAgentData).then((data) => {
734      console.info('cancel success.');
735    }).catch((err: BusinessError) => {
736      console.error(`cancel failed, err code: ${err.code}, err msg: ${err.message}.`);
737    });
738  } catch (err) {
739    let code = (err as BusinessError).code;
740    let msg = (err as BusinessError).message;
741    console.error(`cancel failed, err code: ${code}, err msg: ${msg}.`);
742  }
743}
744
745try {
746  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
747} catch (err) {
748  let code = (err as BusinessError).code;
749  let msg = (err as BusinessError).message;
750  console.error(`getWantAgent failed, err code: ${code}, err msg: ${msg}.`);
751}
752```
753
754## wantAgent.trigger
755
756trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<CompleteData\>): void
757
758主动激发WantAgent实例,使用callback异步回调。
759
760**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
761
762**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
763
764**参数:**
765
766| 参数名        | 类型                          | 必填 | 说明                            |
767| ----------- | ----------------------------- | ---- | ------------------------------- |
768| agent       | WantAgent                     | 是   | WantAgent对象。                   |
769| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md)                   | 是   | 表示触发WantAgent时携带的信息,如自定义的extraInfos。 |
770| callback    | AsyncCallback\<[CompleteData](#completedata)\> | 否   | 主动激发WantAgent实例的回调方法。 |
771
772**错误码:**
773
774以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。
775
776| 错误码ID    | 错误信息            |
777|-----------|--------------------|
778| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
779
780**示例:**
781
782```ts
783import { wantAgent, Want } from '@kit.AbilityKit';
784import type { WantAgent } from '@kit.AbilityKit';
785import { BusinessError } from '@kit.BasicServicesKit';
786
787//wantAgent对象
788let wantAgentData: WantAgent;
789// triggerInfo
790let triggerInfo: wantAgent.TriggerInfo = {
791  code: 0 //自定义结果码
792};
793//WantAgentInfo对象
794let wantAgentInfo: wantAgent.WantAgentInfo = {
795  wants: [
796    {
797      deviceId: 'deviceId',
798      bundleName: 'com.example.myapplication',
799      abilityName: 'EntryAbility',
800      action: 'action1',
801      entities: ['entity1'],
802      type: 'MIMETYPE',
803      uri: 'key={true,true,false}',
804      parameters:
805      {
806        mykey0: 2222,
807        mykey1: [1, 2, 3],
808        mykey2: '[1, 2, 3]',
809        mykey3: 'ssssssssssssssssssssssssss',
810        mykey4: [false, true, false],
811        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
812        mykey6: true,
813      }
814    } as Want
815  ],
816  actionType: wantAgent.OperationType.START_ABILITY,
817  requestCode: 0,
818  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
819};
820
821//getWantAgent回调
822function getWantAgentCallback(err: BusinessError, data: WantAgent) {
823  if (err) {
824    console.info(`getWantAgent failed, code: ${err.code}, message: ${err.message}`);
825  } else {
826    wantAgentData = data;
827  }
828  //trigger回调
829  let triggerCallback = (err: BusinessError, data: wantAgent.CompleteData) => {
830    if (err) {
831      console.error(`trigger failed, code: ${err.code}, message: ${err.message}`);
832    } else {
833      console.info(`trigger success, data: ${JSON.stringify(data)}`);
834    }
835  }
836  try {
837    wantAgent.trigger(wantAgentData, triggerInfo, triggerCallback);
838  } catch (err) {
839    let code = (err as BusinessError).code;
840    let msg = (err as BusinessError).message;
841    console.error(`trigger failed, code: ${code}, message: ${msg}.`);
842  }
843}
844
845try {
846  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
847} catch (err) {
848  let code = (err as BusinessError).code;
849  let msg = (err as BusinessError).message;
850  console.error(`getWantAgent failed, code: ${code}, message: ${msg}.`);
851}
852```
853
854## wantAgent.equal
855
856equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void
857
858判断两个WantAgent实例是否相等,使用callback异步回调,以此来判断是否是来自同一应用的相同操作。
859
860**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
861
862**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
863
864**参数:**
865
866| 参数名       | 类型                     | 必填 | 说明                                    |
867| ---------- | ------------------------ | ---- | --------------------------------------- |
868| agent      | WantAgent                | 是   | WantAgent对象。                           |
869| otherAgent | WantAgent                | 是   | WantAgent对象。                           |
870| callback   | AsyncCallback\<boolean\> | 是   | 判断两个WantAgent实例是否相等的回调方法。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等。 |
871
872**错误码:**
873
874以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。
875
876| 错误码ID    | 错误信息            |
877|-----------|--------------------|
878| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
879
880**示例:**
881
882```ts
883import { wantAgent, Want } from '@kit.AbilityKit';
884import type { WantAgent } from '@kit.AbilityKit';
885import { BusinessError } from '@kit.BasicServicesKit';
886
887//wantAgent对象
888let wantAgent1: WantAgent;
889let wantAgent2: WantAgent;
890//WantAgentInfo对象
891let wantAgentInfo: wantAgent.WantAgentInfo = {
892  wants: [
893    {
894      deviceId: 'deviceId',
895      bundleName: 'com.example.myapplication',
896      abilityName: 'EntryAbility',
897      action: 'action1',
898      entities: ['entity1'],
899      type: 'MIMETYPE',
900      uri: 'key={true,true,false}',
901      parameters:
902      {
903        mykey0: 2222,
904        mykey1: [1, 2, 3],
905        mykey2: '[1, 2, 3]',
906        mykey3: 'ssssssssssssssssssssssssss',
907        mykey4: [false, true, false],
908        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
909        mykey6: true,
910      }
911    } as Want
912  ],
913  actionType: wantAgent.OperationType.START_ABILITY,
914  requestCode: 0,
915  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
916};
917
918//getWantAgent回调
919function getWantAgentCallback(err: BusinessError, data: WantAgent) {
920  if (err) {
921    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
922  } else {
923    wantAgent1 = data;
924    wantAgent2 = data;
925  }
926  //equal回调
927  let equalCallback = (err: BusinessError, data: boolean) => {
928    if (err) {
929      console.error(`equal failed! ${err.code} ${err.message}`);
930    } else {
931      console.info(`equal ok! ${JSON.stringify(data)}`);
932    }
933  }
934  try {
935    wantAgent.equal(wantAgent1, wantAgent2, equalCallback);
936  } catch (err) {
937    console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
938  }
939}
940
941try {
942  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
943} catch (err) {
944  console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
945}
946```
947
948## wantAgent.equal
949
950equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>
951
952判断两个WantAgent实例是否相等,使用Promise异步回调,以此来判断是否是来自同一应用的相同操作。
953
954**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
955
956**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
957
958**参数:**
959
960| 参数名       | 类型      | 必填 | 说明          |
961| ---------- | --------- | ---- | ------------- |
962| agent      | WantAgent | 是   | WantAgent对象。 |
963| otherAgent | WantAgent | 是   | WantAgent对象。 |
964
965**返回值:**
966
967| 类型                                                        | 说明                                                         |
968| ----------------------------------------------------------- | ------------------------------------------------------------ |
969| Promise\<boolean\> | 以Promise形式返回获取判断两个WantAgent实例是否相等的结果。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等。 |
970
971**错误码:**
972
973以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。
974
975| 错误码ID    | 错误信息            |
976|-----------|--------------------|
977| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
978
979**示例:**
980
981```ts
982import { wantAgent, Want } from '@kit.AbilityKit';
983import type { WantAgent } from '@kit.AbilityKit';
984import { BusinessError } from '@kit.BasicServicesKit';
985
986//wantAgent对象
987let wantAgent1: WantAgent;
988let wantAgent2: WantAgent;
989//WantAgentInfo对象
990let wantAgentInfo: wantAgent.WantAgentInfo = {
991  wants: [
992    {
993      deviceId: 'deviceId',
994      bundleName: 'com.example.myapplication',
995      abilityName: 'EntryAbility',
996      action: 'action1',
997      entities: ['entity1'],
998      type: 'MIMETYPE',
999      uri: 'key={true,true,false}',
1000      parameters:
1001      {
1002        mykey0: 2222,
1003        mykey1: [1, 2, 3],
1004        mykey2: '[1, 2, 3]',
1005        mykey3: 'ssssssssssssssssssssssssss',
1006        mykey4: [false, true, false],
1007        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
1008        mykey6: true,
1009      }
1010    } as Want
1011  ],
1012  actionType: wantAgent.OperationType.START_ABILITY,
1013  requestCode: 0,
1014  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1015};
1016
1017//getWantAgent回调
1018function getWantAgentCallback(err: BusinessError, data: WantAgent) {
1019  if (err) {
1020    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
1021  } else {
1022    wantAgent1 = data;
1023    wantAgent2 = data;
1024  }
1025  try {
1026    wantAgent.equal(wantAgent1, wantAgent2).then((data) => {
1027      console.info(`equal ok! ${JSON.stringify(data)}`);
1028    }).catch((err: BusinessError) => {
1029      console.error(`equal failed! ${err.code} ${err.message}`);
1030    })
1031  } catch (err) {
1032    console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
1033  }
1034}
1035
1036try {
1037  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
1038} catch (err) {
1039  console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
1040}
1041```
1042
1043## wantAgent.getOperationType
1044
1045getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void
1046
1047获取一个WantAgent的OperationType信息,使用callback异步回调。
1048
1049**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
1050
1051**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1052
1053**参数:**
1054
1055| 参数名       | 类型                     | 必填 | 说明                                    |
1056| ---------- | ------------------------ | ---- | --------------------------------------- |
1057| agent      | WantAgent                | 是   | WantAgent对象。                           |
1058| callback   | AsyncCallback\<number> | 是   | 获取一个WantAgent的OperationType信息的回调方法。 |
1059
1060**错误码:**
1061
1062以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1063
1064| 错误码ID    | 错误信息            |
1065|-----------|--------------------|
1066| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1067| 16000007   | Service busy. There are concurrent tasks. Try again later. |
1068| 16000015   | Service timeout.|
1069| 16000151   | Invalid wantAgent object.|
1070
1071**示例:**
1072
1073```ts
1074import { wantAgent, Want } from '@kit.AbilityKit';
1075import type { WantAgent } from '@kit.AbilityKit';
1076import { BusinessError } from '@kit.BasicServicesKit';
1077
1078//wantAgent对象
1079let wantAgentData: WantAgent;
1080//WantAgentInfo对象
1081let wantAgentInfo: wantAgent.WantAgentInfo = {
1082  wants: [
1083    {
1084      deviceId: 'deviceId',
1085      bundleName: 'com.example.myapplication',
1086      abilityName: 'EntryAbility',
1087      action: 'action1',
1088      entities: ['entity1'],
1089      type: 'MIMETYPE',
1090      uri: 'key={true,true,false}',
1091      parameters:
1092      {
1093        mykey0: 2222,
1094        mykey1: [1, 2, 3],
1095        mykey2: '[1, 2, 3]',
1096        mykey3: 'ssssssssssssssssssssssssss',
1097        mykey4: [false, true, false],
1098        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
1099        mykey6: true,
1100      }
1101    } as Want
1102  ],
1103  actionType: wantAgent.OperationType.START_ABILITY,
1104  requestCode: 0,
1105  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1106};
1107
1108//getWantAgent回调
1109function getWantAgentCallback(err: BusinessError, data: WantAgent) {
1110  if (err) {
1111    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
1112  } else {
1113    wantAgentData = data;
1114  }
1115  //getOperationTypeCallback回调
1116  let getOperationTypeCallback = (err: BusinessError, data: number) => {
1117    if (err) {
1118      console.error(`getOperationType failed! ${err.code} ${err.message}`);
1119    } else {
1120      console.info(`getOperationType ok! ${JSON.stringify(data)}`);
1121    }
1122  }
1123  try {
1124    wantAgent.getOperationType(wantAgentData, getOperationTypeCallback);
1125  } catch (err) {
1126    console.error(`getOperationTypeCallback failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
1127  }
1128}
1129
1130try {
1131  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
1132} catch (err) {
1133  console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
1134}
1135```
1136
1137## wantAgent.getOperationType
1138
1139getOperationType(agent: WantAgent): Promise\<number>
1140
1141获取一个WantAgent的OperationType信息,使用Promise异步回调。
1142
1143**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
1144
1145**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1146
1147**参数:**
1148
1149| 参数名       | 类型      | 必填 | 说明          |
1150| ---------- | --------- | ---- | ------------- |
1151| agent      | WantAgent | 是   | WantAgent对象。 |
1152
1153**返回值:**
1154
1155| 类型                                                        | 说明                                                         |
1156| ----------------------------------------------------------- | ------------------------------------------------------------ |
1157| Promise\<number> | 以Promise形式返回获取operationType的结果。 |
1158
1159**错误码:**
1160
1161以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1162
1163| 错误码ID    | 错误信息            |
1164|-----------|--------------------|
1165| 401        | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1166| 16000007   | Service busy. There are concurrent tasks. Try again later. |
1167| 16000015   | Service timeout.|
1168| 16000151   | Invalid wantAgent object.|
1169
1170**示例:**
1171
1172```ts
1173import { wantAgent, Want } from '@kit.AbilityKit';
1174import type { WantAgent } from '@kit.AbilityKit';
1175import { BusinessError } from '@kit.BasicServicesKit';
1176
1177//wantAgent对象
1178let wantAgentData: WantAgent;
1179//WantAgentInfo对象
1180let wantAgentInfo: wantAgent.WantAgentInfo = {
1181  wants: [
1182    {
1183      deviceId: 'deviceId',
1184      bundleName: 'com.example.myapplication',
1185      abilityName: 'EntryAbility',
1186      action: 'action1',
1187      entities: ['entity1'],
1188      type: 'MIMETYPE',
1189      uri: 'key={true,true,false}',
1190      parameters:
1191      {
1192        mykey0: 2222,
1193        mykey1: [1, 2, 3],
1194        mykey2: '[1, 2, 3]',
1195        mykey3: 'ssssssssssssssssssssssssss',
1196        mykey4: [false, true, false],
1197        mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
1198        mykey6: true,
1199      }
1200    } as Want
1201  ],
1202  actionType: wantAgent.OperationType.START_ABILITY,
1203  requestCode: 0,
1204  wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1205};
1206
1207//getWantAgent回调
1208function getWantAgentCallback(err: BusinessError, data: WantAgent) {
1209  if (err) {
1210    console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`);
1211  } else {
1212    wantAgentData = data;
1213  }
1214  try {
1215    wantAgent.getOperationType(wantAgentData).then((data) => {
1216      console.info(`getOperationType ok! ${JSON.stringify(data)}`);
1217    }).catch((err: BusinessError) => {
1218      console.error(`getOperationType failed! ${err.code} ${err.message}`);
1219    });
1220  } catch (err) {
1221    console.error(`getOperationType failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
1222  }
1223}
1224
1225try {
1226  wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
1227} catch (err) {
1228  console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`);
1229}
1230```
1231
1232## WantAgentFlags
1233
1234表示使用WantAgent类型的枚举。
1235
1236**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
1237
1238**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1239
1240| 名称                | 值             | 说明                                                                      |
1241| ------------------- | -------------- |-------------------------------------------------------------------------|
1242| ONE_TIME_FLAG       | 0 | WantAgent仅能使用一次。                                                        |
1243| NO_BUILD_FLAG       | 1 | 如果描述WantAgent对象不存在,则不创建它,直接返回null。                                      |
1244| CANCEL_PRESENT_FLAG | 2 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。                                 |
1245| UPDATE_PRESENT_FLAG | 3 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。                                |
1246| CONSTANT_FLAG       | 4 | WantAgent是不可变的。                                                         |
1247| REPLACE_ELEMENT     | 5 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代。当前版本暂不支持。       |
1248| REPLACE_ACTION      | 6 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代。当前版本暂不支持。         |
1249| REPLACE_URI         | 7 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代。当前版本暂不支持。               |
1250| REPLACE_ENTITIES    | 8 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代。当前版本暂不支持。     |
1251| REPLACE_BUNDLE      | 9 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代。当前版本暂不支持。 |
1252
1253
1254
1255## OperationType
1256
1257表示操作WantAgent类型的枚举。
1258
1259**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
1260
1261**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1262
1263| 名称              | 值            | 说明                      |
1264| ----------------- | ------------- | ------------------------- |
1265| UNKNOWN_TYPE      | 0 | 不识别的类型。            |
1266| START_ABILITY     | 1 | 开启一个有页面的Ability。 |
1267| START_ABILITIES   | 2 | 开启多个有页面的Ability。 |
1268| START_SERVICE     | 3 | 开启一个无页面的Ability(仅在FA模型下生效)。 |
1269| SEND_COMMON_EVENT | 4 | 发送一个公共事件。        |
1270
1271
1272
1273## CompleteData
1274
1275表示主动激发WantAgent返回的数据。
1276
1277**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
1278
1279**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1280
1281| 名称 | 类型 | 只读 | 可选 | 说明 |
1282| -------- | -------- | -------- | -------- | -------- |
1283| info           | WantAgent                       | 否 | 否   | 触发的wantAgent。       |
1284| want           | [Want](js-apis-app-ability-want.md)                            | 否 | 否   | 存在的被触发的want。     |
1285| finalCode      | number                          | 否 | 否   | 触发wantAgent的请求代码。 |
1286| finalData      | string                          | 否 | 否   | 公共事件收集的最终数据。  |
1287| extraInfo      | Record\<string, Object>            | 否 |是   | 额外数据。               |
1288
1289## TriggerInfo
1290
1291type TriggerInfo = _TriggerInfo
1292
1293TriggerInfo对象。
1294
1295**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
1296
1297**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1298
1299| 类型 | 说明 |
1300| --- | --- |
1301| [_TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | TriggerInfo对象。 |
1302
1303## WantAgentInfo
1304
1305type WantAgentInfo = _WantAgentInfo
1306
1307WantAgentInfo对象。
1308
1309**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
1310
1311**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1312
1313| 类型 | 说明 |
1314| --- | --- |
1315| [_WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | WantAgentInfo对象。 |
1316
1317## WantAgent
1318
1319type WantAgent = object
1320
1321WantAgent对象。
1322
1323**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1324
1325| 类型 | 说明 |
1326| --- | --- |
1327| object | WantAgent对象。 |
1328