• 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 '@ohos.ability.featureAbility';
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
26Observe the following when using this API:
27 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
28 - If **visible** of the target ability is **false**, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
29 - 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).
30
31**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
32
33**Parameters**
34
35| Name       | Type                                      | Mandatory  | Description            |
36| --------- | ---------------------------------------- | ---- | -------------- |
37| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes   | Ability to start.|
38| callback  | AsyncCallback\<number>                   | Yes   | Callback used to return the result.     |
39
40**Example**
41
42```ts
43import featureAbility from '@ohos.ability.featureAbility';
44import wantConstant from '@ohos.app.ability.wantConstant';
45featureAbility.startAbility(
46    {
47        want:
48        {
49            action: '',
50            entities: [''],
51            type: '',
52            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
53            deviceId: '',
54            bundleName: 'com.example.myapplication',
55            /* In the FA model, abilityName consists of package and ability names. */
56            abilityName: 'com.example.myapplication.secondAbility',
57            uri: ''
58        },
59    },
60    (err, data) => {
61        console.info('startAbility err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
62    }
63);
64```
65
66
67
68## featureAbility.startAbility
69
70startAbility(parameter: StartAbilityParameter): Promise\<number>
71
72Starts an ability. This API uses a promise to return the result.
73
74Observe the following when using this API:
75 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
76 - If **visible** of the target ability is **false**, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
77 - 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).
78
79**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
80
81**Parameters**
82
83| Name       | Type                                      | Mandatory  | Description            |
84| --------- | ---------------------------------------- | ---- | -------------- |
85| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes   | Ability to start.|
86
87**Return value**
88
89| Type                                      | Description     |
90| ---------------------------------------- | ------- |
91| Promise\<number> | Promise used to return the result.|
92
93**Example**
94
95```ts
96import featureAbility from '@ohos.ability.featureAbility';
97import wantConstant from '@ohos.app.ability.wantConstant';
98featureAbility.startAbility(
99    {
100        want:
101        {
102            action: 'ohos.want.action.home',
103            entities: ['entity.system.home'],
104            type: 'MIMETYPE',
105            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
106            deviceId: '',
107            bundleName: 'com.example.myapplication',
108            /* In the FA model, abilityName consists of package and ability names. */
109            abilityName: 'com.example.myapplication.secondAbility',
110            uri: ''
111        },
112    }
113).then((data) => {
114    console.info('startAbility data: ' + JSON.stringify(data));
115});
116```
117
118## featureAbility.acquireDataAbilityHelper<sup>7+</sup>
119
120acquireDataAbilityHelper(uri: string): DataAbilityHelper
121
122Obtains a **dataAbilityHelper** object.
123
124**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
125
126**Parameters**
127
128| Name  | Type    | Mandatory  | Description          |
129| ---- | ------ | ---- | ------------ |
130| uri  | string | Yes   | URI of the file to open.|
131
132**Return value**
133
134| Type               | Description                             |
135| ----------------- | ------------------------------- |
136| [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | A utility class used to help other abilities access the Data ability.|
137
138**Example**
139
140```ts
141import featureAbility from '@ohos.ability.featureAbility';
142let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
143    'dataability:///com.example.DataAbility'
144);
145```
146
147## featureAbility.startAbilityForResult<sup>7+</sup>
148
149startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\<AbilityResult>): void
150
151Starts 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:
152 - Normally, you can call [terminateSelfWithResult](#featureabilityterminateselfwithresult7) to terminate the ability. The result is returned to the caller.
153 - If an exception occurs, for example, the ability is killed, an exception message, in which **resultCode** is **-1**, is returned to the caller.
154 - If different applications call this API to start an ability that uses the sington 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.
155
156Observe the following when using this API:
157 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
158 - If **visible** of the target ability is **false**, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
159 - 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).
160
161**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
162
163**Parameters**
164
165| Name       | Type                                      | Mandatory  | Description            |
166| --------- | ---------------------------------------- | ---- | -------------- |
167| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes   | Ability to start.|
168| callback  | AsyncCallback\<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Yes   | Callback used to return the result.     |
169
170**Example**
171
172```ts
173import featureAbility from '@ohos.ability.featureAbility';
174import wantConstant from '@ohos.app.ability.wantConstant';
175featureAbility.startAbilityForResult(
176   {
177        want:
178        {
179            action: 'ohos.want.action.home',
180            entities: ['entity.system.home'],
181            type: 'MIMETYPE',
182            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
183            deviceId: '',
184            bundleName: 'com.example.myapplication',
185            /* In the FA model, abilityName consists of package and ability names. */
186            abilityName: 'com.example.myapplication.secondAbility',
187            uri:''
188        },
189    },
190    (err, data) => {
191        console.info('startAbilityForResult err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
192    }
193);
194```
195
196## featureAbility.startAbilityForResult<sup>7+</sup>
197
198startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
199
200Starts an ability. This API uses a promise to return the result when the ability is terminated. The following situations may be possible to an ability after it is started:
201 - Normally, you can call [terminateSelfWithResult](#featureabilityterminateselfwithresult7) to terminate the ability. The result is returned to the caller.
202 - If an exception occurs, for example, the ability is killed, an exception message, in which **resultCode** is **-1**, is returned to the caller.
203 - If different applications call this API to start an ability that uses the sington 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.
204
205Observe the following when using this API:
206 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
207 - If **visible** of the target ability is **false**, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
208 - 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).
209
210**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
211
212**Parameters**
213
214| Name       | Type                                      | Mandatory  | Description           |
215| --------- | ---------------------------------------- | ---- | ------------- |
216| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes   | Ability to start.|
217
218**Return value**
219
220| Type                                      | Description     |
221| ---------------------------------------- | ------- |
222| Promise\<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promise used to return the result.|
223
224**Example**
225
226```ts
227import featureAbility from '@ohos.ability.featureAbility';
228import wantConstant from '@ohos.app.ability.wantConstant';
229featureAbility.startAbilityForResult(
230    {
231        want:
232        {
233            action: 'ohos.want.action.home',
234            entities: ['entity.system.home'],
235            type: 'MIMETYPE',
236            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
237            deviceId: '',
238            bundleName: 'com.example.myapplication',
239            /* In the FA model, abilityName consists of package and ability names. */
240            abilityName: 'com.example.myapplication.secondAbility',
241            uri:'',
242            parameters:
243            {
244                mykey0: 1111,
245                mykey1: [1, 2, 3],
246                mykey2: '[1, 2, 3]',
247                mykey3: 'xxxxxxxxxxxxxxxxxxxxxx',
248                mykey4: [1, 15],
249                mykey5: [false, true, false],
250                mykey6: ['aaaaaa', 'bbbbb', 'ccccccccccc'],
251                mykey7: true,
252            },
253        },
254    },
255).then((data) => {
256    console.info('startAbilityForResult data: ' + JSON.stringify(data));
257});
258```
259
260## featureAbility.terminateSelfWithResult<sup>7+</sup>
261
262terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>): void
263
264Terminates this ability. If the ability is started by calling [startAbilityForResult](#featureabilitystartabilityforresult7), the result is returned to the caller in the form of a callback when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
265
266**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
267
268**Parameters**
269
270| Name       | Type                             | Mandatory  | Description            |
271| --------- | ------------------------------- | ---- | -------------- |
272| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes   | Result returned after the ability is terminated.|
273| callback  | AsyncCallback\<void>            | Yes   | Callback used to return the result.     |
274
275**Example**
276
277```ts
278import featureAbility from '@ohos.ability.featureAbility';
279import wantConstant from '@ohos.app.ability.wantConstant';
280featureAbility.terminateSelfWithResult(
281    {
282        resultCode: 1,
283        want:
284        {
285            action: 'ohos.want.action.home',
286            entities: ['entity.system.home'],
287            type: 'MIMETYPE',
288            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
289            deviceId: '',
290            bundleName: 'com.example.myapplication',
291            /* In the FA model, abilityName consists of package and ability names. */
292            abilityName: 'com.example.myapplication.secondAbility',
293            uri:'',
294            parameters: {
295                mykey0: 2222,
296                mykey1: [1, 2, 3],
297                mykey2: '[1, 2, 3]',
298                mykey3: 'ssssssssssssssssssssssssss',
299                mykey4: [1, 15],
300                mykey5: [false, true, false],
301                mykey6: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
302                mykey7: true,
303            }
304        },
305    },
306    (err) => {
307        console.error('err: ' + JSON.stringify(err));
308    }
309);
310```
311
312## featureAbility.terminateSelfWithResult<sup>7+</sup>
313
314terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
315
316Terminates this ability. If the ability is started by calling [startAbilityForResult](#featureabilitystartabilityforresult7), the result is returned to the caller in the form of a promise when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
317
318**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
319
320**Parameters**
321
322| Name       | Type                             | Mandatory  | Description           |
323| --------- | ------------------------------- | ---- | ------------- |
324| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes   | Result returned after the ability is terminated.|
325
326**Return value**
327
328| Type            | Description             |
329| -------------- | --------------- |
330| Promise\<void> | Promise used to return the result.|
331
332**Example**
333
334```ts
335import featureAbility from '@ohos.ability.featureAbility';
336import wantConstant from '@ohos.app.ability.wantConstant';
337featureAbility.terminateSelfWithResult(
338    {
339        resultCode: 1,
340        want:
341        {
342            action: 'ohos.want.action.home',
343            entities: ['entity.system.home'],
344            type: 'MIMETYPE',
345            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
346            deviceId: '',
347            bundleName: 'com.example.myapplication',
348            /* In the FA model, abilityName consists of package and ability names. */
349            abilityName: 'com.example.myapplication.secondAbility',
350            uri:'',
351            parameters: {
352                mykey0: 2222,
353                mykey1: [1, 2, 3],
354                mykey2: '[1, 2, 3]',
355                mykey3: 'ssssssssssssssssssssssssss',
356                mykey4: [1, 15],
357                mykey5: [false, true, false],
358                mykey6: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
359                mykey7: true,
360            }
361        },
362    }
363).then((data) => {
364    console.info('==========================>terminateSelfWithResult=======================>');
365});
366```
367
368## featureAbility.hasWindowFocus<sup>7+</sup>
369
370hasWindowFocus(callback: AsyncCallback\<boolean>): void
371
372Checks whether the main window of this ability has the focus. This API uses an asynchronous callback to return the result.
373
374**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
375
376**Parameters**
377
378| Name      | Type                     | Mandatory  | Description                                      |
379| -------- | ----------------------- | ---- | ---------------------------------------- |
380| 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.|
381
382**Example**
383
384```ts
385import featureAbility from '@ohos.ability.featureAbility';
386featureAbility.hasWindowFocus((err, data) => {
387    console.info('hasWindowFocus err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
388});
389```
390
391## featureAbility.hasWindowFocus<sup>7+</sup>
392
393hasWindowFocus(): Promise\<boolean>
394
395Checks whether the main window of this ability has the focus. This API uses a promise to return the result.
396
397**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
398
399**Return value**
400
401| Type               | Description                                   |
402| ----------------- | ------------------------------------- |
403| Promise\<boolean> | Promise used to return the result. If the main window has the focus, **true** is returned. Otherwise, **false** is returned.|
404
405**Example**
406
407```ts
408import featureAbility from '@ohos.ability.featureAbility';
409featureAbility.hasWindowFocus().then((data) => {
410    console.info('hasWindowFocus data: ' + JSON.stringify(data));
411});
412```
413
414## featureAbility.getWant
415
416getWant(callback: AsyncCallback\<Want>): void
417
418Obtains the Want corresponding to the ability to start. This API uses an asynchronous callback to return the result.
419
420**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
421
422**Parameters**
423
424| Name      | Type                           | Mandatory  | Description       |
425| -------- | ----------------------------- | ---- | --------- |
426| callback | AsyncCallback\<[Want](js-apis-application-want.md)> | Yes   | Callback used to return the Want.|
427
428**Example**
429
430```ts
431import featureAbility from '@ohos.ability.featureAbility';
432featureAbility.getWant((err, data) => {
433    console.info('getWant err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
434});
435```
436
437## featureAbility.getWant
438
439getWant(): Promise\<Want>
440
441Obtains the Want corresponding to the ability to start. This API uses a promise to return the result.
442
443**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
444
445**Return value**
446
447| Type                     | Description              |
448| ----------------------- | ---------------- |
449| Promise\<[Want](js-apis-application-want.md)> | Promise used to return the Want.|
450
451**Example**
452
453```ts
454import featureAbility from '@ohos.ability.featureAbility';
455featureAbility.getWant().then((data) => {
456    console.info('getWant data: ' + JSON.stringify(data));
457});
458```
459
460## featureAbility.getContext
461
462getContext(): Context
463
464Obtains the application context.
465
466**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
467
468**Return value**
469
470| Type     | Description        |
471| ------- | ---------- |
472| Context | Application context.|
473
474**Example**
475
476```ts
477import featureAbility from '@ohos.ability.featureAbility';
478let context = featureAbility.getContext();
479context.getBundleName((err, data) => {
480    console.info('getBundleName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
481});
482```
483
484## featureAbility.terminateSelf<sup>7+</sup>
485
486terminateSelf(callback: AsyncCallback\<void>): void
487
488Terminates this ability. This API uses an asynchronous callback to return the result.
489
490**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
491
492**Parameters**
493
494| Name      | Type                  | Mandatory  | Description      |
495| -------- | -------------------- | ---- | -------- |
496| callback | AsyncCallback\<void> | Yes   | Callback used to return the result.|
497
498**Example**
499
500```ts
501import featureAbility from '@ohos.ability.featureAbility';
502featureAbility.terminateSelf(
503    (err) => {
504        console.error('err: ' + JSON.stringify(err));
505    }
506)
507```
508
509## featureAbility.terminateSelf<sup>7+</sup>
510
511terminateSelf(): Promise\<void>
512
513Terminates this ability. This API uses a promise to return the result.
514
515**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
516
517**Return value**
518
519| Type            | Description              |
520| -------------- | ---------------- |
521| Promise\<void> | Promise used to return the result.|
522
523**Example**
524
525```ts
526import featureAbility from '@ohos.ability.featureAbility';
527featureAbility.terminateSelf().then((data) => {
528    console.info('==========================>terminateSelf=======================>');
529});
530```
531
532## featureAbility.connectAbility<sup>7+</sup>
533
534connectAbility(request: Want, options:ConnectOptions): number
535
536Connects this ability to a ServiceAbility.
537
538**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
539
540**Parameters**
541
542| Name     | Type            | Mandatory  | Description                   |
543| ------- | -------------- | ---- | --------------------- |
544| request | [Want](js-apis-application-want.md)  | Yes   | ServiceAbility to connect.|
545| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes   | Connection options.            |
546
547**Return value**
548
549| Type    | Description                  |
550| ------ | -------------------- |
551| number | ID of the connected ServiceAbility. The ID starts from 0 and is incremented by 1 each time a connection is set up.|
552
553**Example**
554
555```ts
556import rpc from '@ohos.rpc';
557import featureAbility from '@ohos.ability.featureAbility';
558function onConnectCallback(element, remote){
559    console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
560}
561function onDisconnectCallback(element){
562    console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
563}
564function onFailedCallback(code){
565    console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
566}
567let connectId = featureAbility.connectAbility(
568    {
569        deviceId: '',
570        bundleName: 'com.ix.ServiceAbility',
571        abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
572    },
573    {
574        onConnect: onConnectCallback,
575        onDisconnect: onDisconnectCallback,
576        onFailed: onFailedCallback,
577    },
578);
579```
580
581## featureAbility.disconnectAbility<sup>7+</sup>
582
583disconnectAbility(connection: number, callback:AsyncCallback\<void>): void
584
585Disconnects this ability from a specific ServiceAbility. This API uses an asynchronous callback to return the result.
586
587**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
588
589**Parameters**
590
591| Name        | Type                  | Mandatory  | Description                     |
592| ---------- | -------------------- | ---- | ----------------------- |
593| connection | number               | Yes   | ID of the ServiceAbility to disconnect.|
594| callback   | AsyncCallback\<void> | Yes   | Callback used to return the result.               |
595
596**Example**
597
598```ts
599import rpc from '@ohos.rpc';
600import featureAbility from '@ohos.ability.featureAbility';
601function onConnectCallback(element, remote){
602    console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
603}
604function onDisconnectCallback(element){
605    console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
606}
607function onFailedCallback(code){
608    console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code);
609}
610let connectId = featureAbility.connectAbility(
611    {
612        bundleName: 'com.ix.ServiceAbility',
613        abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
614    },
615    {
616        onConnect: onConnectCallback,
617        onDisconnect: onDisconnectCallback,
618        onFailed: onFailedCallback,
619    },
620);
621
622featureAbility.disconnectAbility(connectId, (err) => {
623    console.error('featureAbilityTest disconnectAbility err====>'
624    + ('json err=') + JSON.stringify(err));
625});
626```
627
628## featureAbility.disconnectAbility<sup>7+</sup>
629
630disconnectAbility(connection: number): Promise\<void>
631
632Disconnects this ability from a specific ServiceAbility. This API uses a promise to return the result.
633
634**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
635
636**Parameters**
637
638| Name        | Type    | Mandatory  | Description                     |
639| ---------- | ------ | ---- | ----------------------- |
640| connection | number | Yes   | ID of the ServiceAbility to disconnect.|
641
642**Return value**
643
644| Type            | Description             |
645| -------------- | --------------- |
646| Promise\<void> | Promise used to return the result.|
647
648**Example**
649
650```ts
651import rpc from '@ohos.rpc';
652import featureAbility from '@ohos.ability.featureAbility';
653function onConnectCallback(element, remote){
654    console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
655}
656function onDisconnectCallback(element){
657    console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
658}
659function onFailedCallback(code){
660    console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code);
661}
662let connectId = featureAbility.connectAbility(
663    {
664        bundleName: 'com.ix.ServiceAbility',
665        abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
666    },
667    {
668        onConnect: onConnectCallback,
669        onDisconnect: onDisconnectCallback,
670        onFailed: onFailedCallback,
671    },
672);
673
674featureAbility.disconnectAbility(connectId).then((data) => {
675    console.log('data : '  + data);
676}).catch((error)=>{
677    console.error('featureAbilityTest result errCode : ' + error.code);
678});
679```
680
681
682## featureAbility.getWindow<sup>7+</sup>
683
684getWindow(callback: AsyncCallback\<window.Window>): void
685
686Obtains the window corresponding to this ability. This API uses an asynchronous callback to return the result.
687
688**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
689
690**Parameters**
691
692| Name    | Type                         | Mandatory| Description                         |
693| -------- | ----------------------------- | ---- | ----------------------------- |
694| callback | AsyncCallback\<[window.Window](js-apis-window.md#window)> | Yes  | Callback used to return the window.|
695
696**Example**
697
698```ts
699featureAbility.getWindow((err, data) => {
700    console.info('getWindow err: ' + JSON.stringify(err) + 'data: ' + typeof(data));
701});
702```
703
704## featureAbility.getWindow<sup>7+</sup>
705
706getWindow(): Promise\<window.Window>;
707
708Obtains the window corresponding to this ability. This API uses a promise to return the result.
709
710**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
711
712**Return value**
713
714| Type                   | Description                         |
715| ----------------------- | ----------------------------- |
716| Promise\<[window.Window](js-apis-window.md#window)> | Promise used to return the window.|
717
718**Example**
719
720```ts
721featureAbility.getWindow().then((data) => {
722    console.info('getWindow data: ' + typeof(data));
723});
724```
725
726## AbilityWindowConfiguration
727
728Defines the window configuration corresponding to this ability. The configuration is obtained through **featureAbility.AbilityWindowConfiguration**.
729
730**Example**
731
732```
733featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED
734```
735
736**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
737
738| Name                                    | Value  | Description                                      |
739| ---------------------------------------- | ---- | ---------------------------------------- |
740| WINDOW_MODE_UNDEFINED<sup>7+</sup>       | 0    | The PageAbility is in an undefined window display mode.|
741| WINDOW_MODE_FULLSCREEN<sup>7+</sup>      | 1    | The PageAbility is in full screen mode.   |
742| WINDOW_MODE_SPLIT_PRIMARY<sup>7+</sup>   | 100  | The left screen in horizontal direction or the upper screen in vertical direction is the primary window.|
743| WINDOW_MODE_SPLIT_SECONDARY<sup>7+</sup> | 101  | The right screen in horizontal direction or the lower screen in vertical direction is the secondary window.|
744| WINDOW_MODE_FLOATING<sup>7+</sup>        | 102  | The PageAbility is displayed in floating window mode.|
745
746
747## AbilityStartSetting
748
749Defines the window attribute corresponding to this ability. The **abilityStartSetting** attribute 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**.
750
751The value is obtained through **featureAbility.AbilityStartSetting**.
752
753**Example**
754
755```
756featureAbility.AbilityStartSetting.BOUNDS_KEY
757```
758
759**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
760
761| Name                          | Value             | Description                                      |
762| ---------------------------- | --------------- | ---------------------------------------- |
763| BOUNDS_KEY<sup>7+</sup>      | 'abilityBounds' | Ability window size.|
764| WINDOW_MODE_KEY<sup>7+</sup> | 'windowMode'    | Ability window display mode.|
765| DISPLAY_ID_KEY<sup>7+</sup>  | 'displayId'     | Display device ID.|
766
767## ErrorCode
768
769Enumerates the error codes.
770
771**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
772
773| Name                            | Value   | Description                                      |
774| ------------------------------ | ---- | ---------------------------------------- |
775| NO_ERROR<sup>7+</sup>          | 0    | No error occurs.|
776| INVALID_PARAMETER<sup>7+</sup> | -1   | Invalid parameter.|
777| ABILITY_NOT_FOUND<sup>7+</sup> | -2   | The ability is not found.|
778| PERMISSION_DENY<sup>7+</sup>   | -3   | Permission denied.|
779
780
781## DataAbilityOperationType
782
783Enumerates the operation types of a DataAbility. The DataAbility can use an enumerated value to specify the operation type when operating data in batches.
784
785**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
786
787| Name                      | Value   | Description                                      |
788| ------------------------ | ---- | ---------------------------------------- |
789| TYPE_INSERT<sup>7+</sup> | 1    | Insert operation.|
790| TYPE_UPDATE<sup>7+</sup> | 2    | Update operation.|
791| TYPE_DELETE<sup>7+</sup> | 3    | Deletion operation.|
792| TYPE_ASSERT<sup>7+</sup> | 4    | Assert operation.|
793
794## flags
795
796Enumerates the flags that specify how the Want will be handled.
797
798**System capability**: SystemCapability.Ability.AbilityBase
799
800| Name                                  | Value        | Description                                      |
801| ------------------------------------ | ---------- | ---------------------------------------- |
802| FLAG_AUTH_READ_URI_PERMISSION        | 0x00000001 | Grants the permission to read the URI.                        |
803| FLAG_AUTH_WRITE_URI_PERMISSION       | 0x00000002 | Grants the permission to write data to the URI.                        |
804| FLAG_ABILITY_FORWARD_RESULT          | 0x00000004 | Returns the result to the ability.                              |
805| FLAG_ABILITY_CONTINUATION            | 0x00000008 | Continues the ability on a remote device.                 |
806| FLAG_NOT_OHOS_COMPONENT              | 0x00000010 | Indicates that a component does not belong to OHOS.                           |
807| FLAG_ABILITY_FORM_ENABLED            | 0x00000020 | Indicates whether the FormAbility is enabled.                             |
808| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Grants the permission to make the URI persistent.<br>**System API**: This is a system API and cannot be called by third-party applications.                         |
809| FLAG_AUTH_PREFIX_URI_PERMISSION      | 0x00000080 | Grants the permission to verify URIs by prefix matching.<br>**System API**: This is a system API and cannot be called by third-party applications.                       |
810| FLAG_ABILITYSLICE_MULTI_DEVICE       | 0x00000100 | Indicates the support for cross-device startup in the distributed scheduler.                       |
811| FLAG_START_FOREGROUND_ABILITY        | 0x00000200 | Indicates that the ability is started in the foreground regardless of whether the host application is started.<br>**System API**: This is a system API and cannot be called by third-party applications.          |
812| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.                              |
813| FLAG_INSTALL_ON_DEMAND               | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.                      |
814| FLAG_INSTALL_WITH_BACKGROUND_MODE    | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed.                      |
815| FLAG_ABILITY_CLEAR_MISSION           | 0x00008000 | Clears other operation missions. This flag can be set for the [Want](js-apis-application-want.md) object under [parameter](js-apis-inner-ability-startAbilityParameter.md) in the [startAbility](#featureabilitystartability) API passed to the **FeatureAbility** module and must be used together with **flag_ABILITY_NEW_MISSION**.|
816| FLAG_ABILITY_NEW_MISSION             | 0x10000000 | Creates a mission on an existing mission stack.                      |
817| FLAG_ABILITY_MISSION_TOP             | 0x20000000 | Reuses an ability instance if it is on the top of an existing mission stack; creates an ability instance otherwise.|
818