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