• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.ability.featureAbility (FeatureAbility)
2
3The **FeatureAbility** module provides APIs that enable user interaction. You can use the APIs to start or terminate an ability, obtain a **dataAbilityHelper** object, obtain the window corresponding to the current ability, and connect to or disconnect from a ServiceAbility.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> The APIs of this module can be used only in the FA model.
9
10## Constraints
11
12The APIs of the **FeatureAbility** module can be called only by PageAbilities.
13
14## Modules to Import
15
16```ts
17import { featureAbility } from '@kit.AbilityKit';
18```
19
20## featureAbility.startAbility
21
22startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>): void
23
24Starts an ability. This API uses an asynchronous callback to return the result.
25
26> **NOTE**
27>
28> For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
29
30**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
31
32**Note**: This API can be used only in the FA model.
33
34**Parameters**
35
36| Name       | Type                                      | Mandatory  | Description            |
37| --------- | ---------------------------------------- | ---- | -------------- |
38| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes   | Ability to start.|
39| callback  | AsyncCallback\<number>                   | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **0**; otherwise, **err** is a non-zero value.     |
40
41**Example**
42
43<!--code_no_check_fa-->
44```ts
45import { featureAbility, wantConstant } from '@kit.AbilityKit';
46
47featureAbility.startAbility(
48  {
49    want:
50    {
51      action: '',
52      entities: [''],
53      type: '',
54      flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
55      deviceId: '',
56      bundleName: 'com.example.myapplication',
57      /* In the FA model, abilityName consists of package and ability names. */
58      abilityName: 'com.example.myapplication.secondAbility',
59      uri: ''
60    },
61  },
62  (error, data) => {
63    if (error && error.code !== 0) {
64      console.error(`startAbility fail, error: ${JSON.stringify(error)}`);
65    } else {
66      console.log(`startAbility success, data: ${JSON.stringify(data)}`);
67    }
68  }
69);
70```
71
72
73
74## featureAbility.startAbility
75
76startAbility(parameter: StartAbilityParameter): Promise\<number>
77
78Starts an ability. This API uses a promise to return the result.
79
80> **NOTE**
81>
82> For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
83
84**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
85
86**Note**: This API can be used only in the FA model.
87
88**Parameters**
89
90| Name       | Type                                      | Mandatory  | Description            |
91| --------- | ---------------------------------------- | ---- | -------------- |
92| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes   | Ability to start.|
93
94**Return value**
95
96| Type                                      | Description     |
97| ---------------------------------------- | ------- |
98| Promise\<number> | Promise used to return the result. If the operation is successful, **0** is returned; otherwise, a non-zero value is returned.|
99
100**Example**
101
102<!--code_no_check_fa-->
103```ts
104import { featureAbility, wantConstant } from '@kit.AbilityKit';
105
106featureAbility.startAbility(
107  {
108    want:
109    {
110      action: 'ohos.want.action.home',
111      entities: ['entity.system.home'],
112      type: 'MIMETYPE',
113      flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
114      deviceId: '',
115      bundleName: 'com.example.myapplication',
116      /* In the FA model, abilityName consists of package and ability names. */
117      abilityName: 'com.example.myapplication.secondAbility',
118      uri: ''
119    },
120  }
121).then((data) => {
122  console.info(`startAbility data: ${JSON.stringify(data)}`);
123});
124```
125
126## featureAbility.acquireDataAbilityHelper<sup>7+</sup>
127
128acquireDataAbilityHelper(uri: string): DataAbilityHelper
129
130Obtains a **dataAbilityHelper** object.
131
132> **NOTE**
133>
134> For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
135> To access a DataAbility of another application, the target application must be configured with associated startup (**AssociateWakeUp** set to **true**).
136
137
138**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
139
140**Note**: This API can be used only in the FA model.
141
142**Parameters**
143
144| Name  | Type    | Mandatory  | Description          |
145| ---- | ------ | ---- | ------------ |
146| uri  | string | Yes   | URI of the file to open.|
147
148**Return value**
149
150| Type               | Description                             |
151| ----------------- | ------------------------------- |
152| [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | A utility class used to help other abilities access the Data ability.|
153
154**Example**
155
156<!--code_no_check_fa-->
157```ts
158import { featureAbility } from '@kit.AbilityKit';
159
160let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
161  'dataability:///com.example.DataAbility'
162);
163```
164
165## featureAbility.startAbilityForResult<sup>7+</sup>
166
167startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\<AbilityResult>): void
168
169Starts an ability. This API uses an asynchronous callback to return the result when the ability is terminated. The following situations may be possible for a started ability:
170 - Normally, you can call [terminateSelfWithResult](#featureabilityterminateselfwithresult7) to terminate the ability. The result is returned to the caller.
171 - If an exception occurs, for example, the ability is killed, an exception message, in which **resultCode** is **-1**, is returned to the caller.
172 - If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](#featureabilityterminateselfwithresult7) to terminate the ability, the normal result is returned to the last caller, and an exception message, in which **resultCode** is **-1**, is returned to others.
173
174> **NOTE**
175>
176> For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
177
178**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
179
180**Note**: This API can be used only in the FA model.
181
182
183**Parameters**
184
185| Name       | Type                                      | Mandatory  | Description            |
186| --------- | ---------------------------------------- | ---- | -------------- |
187| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes   | Ability to start.|
188| callback  | AsyncCallback\<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is an **AbilityResult** object; otherwise, err is an error object.     |
189
190**Example**
191
192<!--code_no_check_fa-->
193```ts
194import { featureAbility, wantConstant } from '@kit.AbilityKit';
195
196featureAbility.startAbilityForResult(
197  {
198    want:
199    {
200      action: 'ohos.want.action.home',
201      entities: ['entity.system.home'],
202      type: 'MIMETYPE',
203      flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
204      deviceId: '',
205      bundleName: 'com.example.myapplication',
206      /* In the FA model, abilityName consists of package and ability names. */
207      abilityName: 'com.example.myapplication.secondAbility',
208      uri: ''
209    },
210  },
211  (error, data) => {
212    if (error && error.code !== 0) {
213      console.error(`startAbilityForResult fail, error: ${JSON.stringify(error)}`);
214    } else {
215      console.log(`startAbilityForResult success, data: ${JSON.stringify(data)}`);
216    }
217  }
218);
219```
220
221## featureAbility.startAbilityForResult<sup>7+</sup>
222
223startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
224
225Starts an ability. This API uses a promise to return the result when the ability is terminated. The following situations may be possible for a started ability:
226 - Normally, you can call [terminateSelfWithResult](#featureabilityterminateselfwithresult7) to terminate the ability. The result is returned to the caller.
227 - If an exception occurs, for example, the ability is killed, an exception message, in which **resultCode** is **-1**, is returned to the caller.
228 - If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](#featureabilityterminateselfwithresult7) to terminate the ability, the normal result is returned to the last caller, and an exception message, in which **resultCode** is **-1**, is returned to others.
229
230> **NOTE**
231>
232> For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
233
234**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
235
236**Note**: This API can be used only in the FA model.
237**Parameters**
238
239| Name       | Type                                      | Mandatory  | Description           |
240| --------- | ---------------------------------------- | ---- | ------------- |
241| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes   | Ability to start.|
242
243**Return value**
244
245| Type                                      | Description     |
246| ---------------------------------------- | ------- |
247| Promise\<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promise used to return the result.|
248
249**Example**
250
251<!--code_no_check_fa-->
252```ts
253import { featureAbility, wantConstant } from '@kit.AbilityKit';
254
255featureAbility.startAbilityForResult(
256  {
257    want:
258    {
259      action: 'ohos.want.action.home',
260      entities: ['entity.system.home'],
261      type: 'MIMETYPE',
262      flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
263      deviceId: '',
264      bundleName: 'com.example.myapplication',
265      /* In the FA model, abilityName consists of package and ability names. */
266      abilityName: 'com.example.myapplication.secondAbility',
267      uri: '',
268      parameters:
269      {
270        mykey0: 1111,
271        mykey1: [1, 2, 3],
272        mykey2: '[1, 2, 3]',
273        mykey3: 'xxxxxxxxxxxxxxxxxxxxxx',
274        mykey4: [1, 15],
275        mykey5: [false, true, false],
276        mykey6: ['aaaaaa', 'bbbbb', 'ccccccccccc'],
277        mykey7: true,
278      },
279    },
280  },
281).then((data) => {
282  console.info(`startAbilityForResult data: ${JSON.stringify(data)}`);
283});
284```
285
286## featureAbility.terminateSelfWithResult<sup>7+</sup>
287
288terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>): void
289
290Terminates this ability. This API uses an asynchronous callback to return the result. If the ability is started by calling [startAbilityForResult](#featureabilitystartabilityforresult7), the result is returned to the caller when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
291
292**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
293
294**Note**: This API can be used only in the FA model.
295
296**Parameters**
297
298| Name       | Type                             | Mandatory  | Description            |
299| --------- | ------------------------------- | ---- | -------------- |
300| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes   | Result returned after the ability is terminated.|
301| callback  | AsyncCallback\<void>            | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.     |
302
303**Example**
304
305<!--code_no_check_fa-->
306```ts
307import { featureAbility, wantConstant } from '@kit.AbilityKit';
308
309featureAbility.terminateSelfWithResult(
310  {
311    resultCode: 1,
312    want:
313    {
314      action: 'ohos.want.action.home',
315      entities: ['entity.system.home'],
316      type: 'MIMETYPE',
317      flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
318      deviceId: '',
319      bundleName: 'com.example.myapplication',
320      /* In the FA model, abilityName consists of package and ability names. */
321      abilityName: 'com.example.myapplication.secondAbility',
322      uri: '',
323      parameters: {
324        mykey0: 2222,
325        mykey1: [1, 2, 3],
326        mykey2: '[1, 2, 3]',
327        mykey3: 'ssssssssssssssssssssssssss',
328        mykey4: [1, 15],
329        mykey5: [false, true, false],
330        mykey6: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
331        mykey7: true,
332      }
333    },
334  },
335  (error) => {
336    console.error(`error: ${JSON.stringify(error)}`);
337  }
338);
339```
340
341## featureAbility.terminateSelfWithResult<sup>7+</sup>
342
343terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
344
345Terminates this ability. This API uses a promise to return the result. If the ability is started by calling [startAbilityForResult](#featureabilitystartabilityforresult7), the result is returned to the caller when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
346
347**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
348
349**Note**: This API can be used only in the FA model.
350
351**Parameters**
352
353| Name       | Type                             | Mandatory  | Description           |
354| --------- | ------------------------------- | ---- | ------------- |
355| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes   | Result returned after the ability is terminated.|
356
357**Return value**
358
359| Type            | Description             |
360| -------------- | --------------- |
361| Promise\<void> | Promise that returns no value.|
362
363**Example**
364
365<!--code_no_check_fa-->
366```ts
367import { featureAbility, wantConstant } from '@kit.AbilityKit';
368
369featureAbility.terminateSelfWithResult(
370  {
371    resultCode: 1,
372    want:
373    {
374      action: 'ohos.want.action.home',
375      entities: ['entity.system.home'],
376      type: 'MIMETYPE',
377      flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
378      deviceId: '',
379      bundleName: 'com.example.myapplication',
380      /* In the FA model, abilityName consists of package and ability names. */
381      abilityName: 'com.example.myapplication.secondAbility',
382      uri:'',
383      parameters: {
384        mykey0: 2222,
385        mykey1: [1, 2, 3],
386        mykey2: '[1, 2, 3]',
387        mykey3: 'ssssssssssssssssssssssssss',
388        mykey4: [1, 15],
389        mykey5: [false, true, false],
390        mykey6: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
391        mykey7: true,
392      }
393    },
394  }
395).then(() => {
396  console.info('==========================>terminateSelfWithResult=======================>');
397});
398```
399
400## featureAbility.hasWindowFocus<sup>7+<sup>
401
402hasWindowFocus(callback: AsyncCallback\<boolean>): void
403
404Checks whether the main window of this ability has the focus. This API uses an asynchronous callback to return the result.
405
406**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
407
408**Note**: This API can be used only in the FA model.
409
410**Parameters**
411
412| Name      | Type                     | Mandatory  | Description                                      |
413| -------- | ----------------------- | ---- | ---------------------------------------- |
414| callback | AsyncCallback\<boolean> | Yes   |Callback used to return the result.<br>If the main window has the focus, **true** is returned. Otherwise, **false** is returned.|
415
416**Example**
417
418<!--code_no_check_fa-->
419```ts
420import { featureAbility } from '@kit.AbilityKit';
421
422featureAbility.hasWindowFocus((error, data) => {
423  if (error && error.code !== 0) {
424    console.error(`hasWindowFocus fail, error: ${JSON.stringify(error)}`);
425  } else {
426    console.log(`hasWindowFocus success, data: ${JSON.stringify(data)}`);
427  }
428});
429```
430
431## featureAbility.hasWindowFocus<sup>7+<sup>
432
433hasWindowFocus(): Promise\<boolean>
434
435Checks whether the main window of this ability has the focus. This API uses a promise to return the result.
436
437**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
438
439**Return value**
440
441| Type               | Description                                   |
442| ----------------- | ------------------------------------- |
443| Promise\<boolean> | Promise used to return the result. If the main window has the focus, **true** is returned. Otherwise, **false** is returned.|
444
445**Example**
446
447<!--code_no_check_fa-->
448```ts
449import { featureAbility } from '@kit.AbilityKit';
450
451featureAbility.hasWindowFocus().then((data) => {
452  console.info(`hasWindowFocus data: ${JSON.stringify(data)}`);
453});
454```
455
456## featureAbility.getWant
457
458getWant(callback: AsyncCallback\<Want>): void
459
460Obtains the Want corresponding to the ability to start. This API uses an asynchronous callback to return the result.
461
462**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
463
464**Note**: This API can be used only in the FA model.
465
466**Parameters**
467
468| Name      | Type                           | Mandatory  | Description       |
469| -------- | ----------------------------- | ---- | --------- |
470| callback | AsyncCallback\<[Want](js-apis-application-want.md)> | Yes   | Callback used to return the Want.|
471
472**Example**
473
474<!--code_no_check_fa-->
475```ts
476import { featureAbility } from '@kit.AbilityKit';
477
478featureAbility.getWant((error, data) => {
479  if (error && error.code !== 0) {
480    console.error(`getWant fail, error: ${JSON.stringify(error)}`);
481  } else {
482    console.log(`getWant success, data: ${JSON.stringify(data)}`);
483  }
484});
485```
486
487## featureAbility.getWant
488
489getWant(): Promise\<Want>
490
491Obtains the Want corresponding to the ability to start. This API uses a promise to return the result.
492
493**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
494
495**Note**: This API can be used only in the FA model.
496
497**Return value**
498
499| Type                     | Description              |
500| ----------------------- | ---------------- |
501| Promise\<[Want](js-apis-application-want.md)> | Promise used to return the Want.|
502
503**Example**
504
505<!--code_no_check_fa-->
506```ts
507import { featureAbility } from '@kit.AbilityKit';
508
509featureAbility.getWant().then((data) => {
510  console.info(`getWant data: ${JSON.stringify(data)}`);
511});
512```
513
514## featureAbility.getContext
515
516getContext(): Context
517
518Obtains the application context.
519
520**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
521
522**Note**: This API can be used only in the FA model.
523
524**Return value**
525
526| Type     | Description        |
527| ------- | ---------- |
528| Context | Application context.|
529
530**Example**
531
532<!--code_no_check_fa-->
533```ts
534import { featureAbility } from '@kit.AbilityKit';
535
536let context = featureAbility.getContext();
537context.getBundleName((error, data) => {
538  if (error && error.code !== 0) {
539    console.error(`getBundleName fail, error: ${JSON.stringify(error)}`);
540  } else {
541    console.log(`getBundleName success, data: ${JSON.stringify(data)}`);
542  }
543});
544```
545
546## featureAbility.terminateSelf<sup>7+</sup>
547
548terminateSelf(callback: AsyncCallback\<void>): void
549
550Terminates this ability. This API uses an asynchronous callback to return the result.
551
552**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
553
554**Note**: This API can be used only in the FA model.
555
556**Parameters**
557
558| Name      | Type                  | Mandatory  | Description      |
559| -------- | -------------------- | ---- | -------- |
560| callback | AsyncCallback\<void> | Yes   | Callback used to return the result. If the ability is terminated, **err** is **undefined**; otherwise, **err** is an error object.|
561
562**Example**
563
564<!--code_no_check_fa-->
565```ts
566import { featureAbility } from '@kit.AbilityKit';
567
568featureAbility.terminateSelf(
569  (error) => {
570    console.error(`error: ${JSON.stringify(error)}`);
571  }
572)
573```
574
575## featureAbility.terminateSelf<sup>7+</sup>
576
577terminateSelf(): Promise\<void>
578
579Terminates this ability. This API uses a promise to return the result.
580
581**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
582
583**Note**: This API can be used only in the FA model.
584
585**Return value**
586
587| Type            | Description              |
588| -------------- | ---------------- |
589| Promise\<void> | Promise that returns no value.|
590
591**Example**
592
593<!--code_no_check_fa-->
594```ts
595import { featureAbility } from '@kit.AbilityKit';
596
597featureAbility.terminateSelf().then(() => {
598  console.info('==========================>terminateSelf=======================>');
599});
600```
601
602## featureAbility.connectAbility<sup>7+</sup>
603
604connectAbility(request: Want, options:ConnectOptions): number
605
606Connects this ability to a ServiceAbility.
607
608> **NOTE**
609>
610> For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
611> To connect to a ServiceAbility of another application, the target application must be configured with associated startup (**AssociateWakeUp** set to **true**).
612
613
614**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
615
616**Note**: This API can be used only in the FA model.
617
618**Parameters**
619
620| Name     | Type            | Mandatory  | Description                   |
621| ------- | -------------- | ---- | --------------------- |
622| request | [Want](js-apis-application-want.md)  | Yes   | ServiceAbility to connect.|
623| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes   | Connection options.            |
624
625**Return value**
626
627| Type    | Description                  |
628| ------ | -------------------- |
629| number | ID of the connected ServiceAbility. The ID starts from 0 and is incremented by 1 each time a connection is set up.|
630
631**Example**
632
633<!--code_no_check_fa-->
634```ts
635import { featureAbility } from '@kit.AbilityKit';
636import { rpc } from '@kit.IPCKit';
637
638let connectId = featureAbility.connectAbility(
639  {
640    deviceId: '',
641    bundleName: 'com.ix.ServiceAbility',
642    abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
643  },
644  {
645    onConnect: (element, remote) => {
646      console.log(`ConnectAbility onConnect remote is proxy: ${(remote instanceof rpc.RemoteProxy)}`);
647    },
648    onDisconnect: (element) => {
649      console.log(`ConnectAbility onDisconnect element.deviceId : ${element.deviceId}`)
650    },
651    onFailed: (code) => {
652      console.error(`featureAbilityTest ConnectAbility onFailed errCode : ${code}`)
653    },
654  },
655);
656```
657
658## featureAbility.disconnectAbility<sup>7+</sup>
659
660disconnectAbility(connection: number, callback:AsyncCallback\<void>): void
661
662Disconnects this ability from a specific ServiceAbility. This API uses an asynchronous callback to return the result.
663
664**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
665
666**Note**: This API can be used only in the FA model.
667
668**Parameters**
669
670| Name        | Type                  | Mandatory  | Description                     |
671| ---------- | -------------------- | ---- | ----------------------- |
672| connection | number               | Yes   | ID of the ServiceAbility to disconnect.|
673| callback   | AsyncCallback\<void> | Yes   | Callback used to return the result. If the disconnection is successful, **err** is **undefined**. Otherwise, **err** is an error object.     |
674
675**Example**
676
677<!--code_no_check_fa-->
678```ts
679import { featureAbility } from '@kit.AbilityKit';
680import { rpc } from '@kit.IPCKit';
681
682let connectId = featureAbility.connectAbility(
683  {
684    bundleName: 'com.ix.ServiceAbility',
685    abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
686  },
687  {
688    onConnect: (element, remote) => {
689      console.log(`ConnectAbility onConnect remote is proxy: ${(remote instanceof rpc.RemoteProxy)}`);
690    },
691    onDisconnect: (element) => {
692      console.log(`ConnectAbility onDisconnect element.deviceId : ${element.deviceId}`);
693    },
694    onFailed: (code) => {
695      console.error(`featureAbilityTest ConnectAbility onFailed errCode : ${code}`);
696    },
697  },
698);
699
700featureAbility.disconnectAbility(connectId, (error) => {
701  if (error && error.code !== 0) {
702    console.error(`disconnectAbility fail, connectId: ${connectId}, error: ${JSON.stringify(error)}`);
703  } else {
704    console.log(`disconnectAbility success, connectId: ${connectId}`);
705  }
706});
707```
708
709## featureAbility.disconnectAbility<sup>7+</sup>
710
711disconnectAbility(connection: number): Promise\<void>
712
713Disconnects this ability from a specific a ServiceAbility. This API uses a promise to return the result.
714
715**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
716
717**Note**: This API can be used only in the FA model.
718
719**Parameters**
720
721| Name        | Type    | Mandatory  | Description                     |
722| ---------- | ------ | ---- | ----------------------- |
723| connection | number | Yes   | ID of the ServiceAbility to disconnect.|
724
725**Return value**
726
727| Type            | Description             |
728| -------------- | --------------- |
729| Promise\<void> | Promise that returns no value.|
730
731**Example**
732
733<!--code_no_check_fa-->
734```ts
735import { featureAbility } from '@kit.AbilityKit';
736import { rpc } from '@kit.IPCKit';
737import { BusinessError } from '@kit.BasicServicesKit';
738
739let connectId = featureAbility.connectAbility(
740  {
741    bundleName: 'com.ix.ServiceAbility',
742    abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
743  },
744  {
745    onConnect: (element, remote) => {
746      console.log(`ConnectAbility onConnect remote is proxy: ${(remote instanceof rpc.RemoteProxy)}`);
747    },
748    onDisconnect: (element) => {
749      console.log(`ConnectAbility onDisconnect element.deviceId : ${element.deviceId}`);
750    },
751    onFailed: (code) => {
752      console.error(`featureAbilityTest ConnectAbility onFailed errCode : ${code}`);
753    },
754  },
755);
756
757featureAbility.disconnectAbility(connectId).then(() => {
758  console.log('disconnectAbility success')
759}).catch((error: BusinessError)=>{
760  console.error(`featureAbilityTest result errCode : ${error.code}`);
761});
762```
763
764
765## featureAbility.getWindow<sup>7+</sup>
766
767getWindow(callback: AsyncCallback\<window.Window>): void
768
769Obtains the window corresponding to this ability. This API uses an asynchronous callback to return the result.
770
771**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
772
773**Note**: This API can be used only in the FA model.
774
775**Parameters**
776
777| Name    | Type                         | Mandatory| Description                         |
778| -------- | ----------------------------- | ---- | ----------------------------- |
779| callback | AsyncCallback\<[window.Window](../apis-arkui/js-apis-window.md#window)> | Yes  | Callback used to return the window.|
780
781**Example**
782
783<!--code_no_check_fa-->
784```ts
785import { featureAbility } from '@kit.AbilityKit';
786import { window } from '@kit.ArkUI';
787import { BusinessError } from '@kit.BasicServicesKit';
788
789featureAbility.getWindow((error: BusinessError, data: window.Window) => {
790  if (error && error.code !== 0) {
791    console.error(`getWindow fail, error: ${JSON.stringify(error)}`);
792  } else {
793    console.log(`getWindow success, data: ${typeof(data)}`);
794  }
795});
796```
797
798## featureAbility.getWindow<sup>7+</sup>
799
800getWindow(): Promise\<window.Window>
801
802Obtains the window corresponding to this ability. This API uses a promise to return the result.
803
804**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
805
806**Note**: This API can be used only in the FA model.
807
808**Return value**
809
810| Type                   | Description                         |
811| ----------------------- | ----------------------------- |
812| Promise\<[window.Window](../apis-arkui/js-apis-window.md#window)> | Promise used to return the window.|
813
814**Example**
815
816<!--code_no_check_fa-->
817```ts
818import { featureAbility } from '@kit.AbilityKit';
819import { window } from '@kit.ArkUI';
820import { BusinessError } from '@kit.BasicServicesKit';
821
822featureAbility.getWindow().then((data: window.Window) => {
823  console.log(`getWindow success, data: ${typeof(data)}`);
824}).catch((error: BusinessError)=>{
825  console.error(`getWindow fail, error: ${JSON.stringify(error)}`);
826});
827```
828
829## AbilityWindowConfiguration<sup>7+</sup>
830
831Defines the window configuration corresponding to this ability. The configuration is obtained through **featureAbility.AbilityWindowConfiguration**.
832
833**Example**
834
835<!--code_no_check_fa-->
836```ts
837import { featureAbility } from '@kit.AbilityKit';
838
839featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED
840```
841
842**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
843
844| Name                                    | Value  | Description                                      |
845| ---------------------------------------- | ---- | ---------------------------------------- |
846| WINDOW_MODE_UNDEFINED       | 0    | The PageAbility is in an undefined window display mode.|
847| WINDOW_MODE_FULLSCREEN      | 1    | The PageAbility is in full screen mode.   |
848| WINDOW_MODE_SPLIT_PRIMARY   | 100  | The left screen in horizontal direction or the upper screen in vertical direction is the primary window.|
849| WINDOW_MODE_SPLIT_SECONDARY | 101  | The right screen in horizontal direction or the lower screen in vertical direction is the secondary window.|
850| WINDOW_MODE_FLOATING        | 102  | The PageAbility is displayed in floating window mode.|
851
852
853## AbilityStartSetting<sup>7+</sup>
854
855Defines the window property corresponding to this ability. The **abilityStartSetting** property is an object defined in the format of [**key: string]: any**, where **key** is an enumerated value of **AbilityStartSetting** and **value** is an enumerated value of **AbilityWindowConfiguration**.
856
857The value is obtained through **featureAbility.AbilityStartSetting**.
858
859**Example**
860
861<!--code_no_check_fa-->
862```ts
863import { featureAbility } from '@kit.AbilityKit';
864
865featureAbility.AbilityStartSetting.BOUNDS_KEY
866```
867
868**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
869
870| Name                          | Value             | Description                                      |
871| ---------------------------- | --------------- | ---------------------------------------- |
872| BOUNDS_KEY      | 'abilityBounds' | Ability window size.|
873| WINDOW_MODE_KEY | 'windowMode'    | Ability window display mode.|
874| DISPLAY_ID_KEY  | 'displayId'     | Display device ID.|
875
876## ErrorCode<sup>7+</sup>
877
878Enumerates the error codes that may be returned when an ability is started.
879
880**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
881
882| Name                            | Value   | Description                                      |
883| ------------------------------ | ---- | ---------------------------------------- |
884| NO_ERROR         | 0    | No error.  |
885| INVALID_PARAMETER | -1   | Invalid parameter.|
886| ABILITY_NOT_FOUND | -2   | The ability is not found.|
887| PERMISSION_DENY   | -3   | Permission denied.  |
888
889## DataAbilityOperationType<sup>7+</sup>
890
891Enumerates the operation types of a DataAbility. The DataAbility can use an enumerated value to specify the operation type when operating data in batches.
892
893**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
894
895| Name                      | Value   | Description                                      |
896| ------------------------ | ---- | ---------------------------------------- |
897| TYPE_INSERT | 1    | Insert operation.|
898| TYPE_UPDATE | 2    | Update operation.|
899| TYPE_DELETE | 3    | Deletion operation.|
900| TYPE_ASSERT | 4    | Assert operation.|
901