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