1# Ability Context 2 3> **NOTE** 4> The initial APIs of this module are supported since API version 9. API version 9 is a canary version for trial use. The APIs of this version may be unstable. 5 6Implements the ability context. This module is inherited from **Context**. 7 8# Modules to Import 9 10```js 11import Ability from '@ohos.application.Ability' 12``` 13 14## Usage 15Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**. 16```js 17import Ability from '@ohos.application.Ability' 18class MainAbility extends Ability { 19 onWindowStageCreate(windowStage) { 20 let context = this.context; 21 } 22} 23``` 24 25## Attributes 26 27**System capability**: SystemCapability.Ability.AbilityRuntime.Core 28 29| Name | Type | Readable | Writable | Description | 30| --------------------- | --------------- | ------ | ------- | ----------------------------------- | 31| config | Configuration | Yes | No | Configuration. | 32| abilityInfo | AbilityInfo | Yes | No | Ability information. | 33| currentHapModuleInfo | HapModuleInfo | Yes | No | Information about the current HAP. | 34 35 36## startAbility 37 38startAbility(want: Want, callback: AsyncCallback<void>): void 39 40Starts an ability. This API uses an asynchronous callback to return the result. 41 42**System capability**: SystemCapability.Ability.AbilityRuntime.Core 43 44**Parameters** 45 46| Name| Type| Mandatory| Description| 47| -------- | -------- | -------- | -------- | 48| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 49| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 50 51**Example** 52 53```js 54var want = { 55 "deviceId": "", 56 "bundleName": "com.extreme.test", 57 "abilityName": "com.extreme.test.MainAbility" 58}; 59this.context.startAbility(want, (error) => { 60 console.log("error.code = " + error.code) 61}) 62``` 63 64## startAbility 65 66startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void 67 68Starts an ability with **options** specified. This API uses an asynchronous callback to return the result. 69 70**System capability**: SystemCapability.Ability.AbilityRuntime.Core 71 72**Parameters** 73 74| Name| Type| Mandatory| Description| 75| -------- | -------- | -------- | -------- | 76| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 77| options | StartOptions | Yes| Parameters used for starting the ability.| 78| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 79 80**Example** 81 82```js 83var want = { 84 "deviceId": "", 85 "bundleName": "com.extreme.test", 86 "abilityName": "com.extreme.test.MainAbility" 87}; 88var options = { 89 windowMode: 0, 90}; 91this.context.startAbility(want, options, (error) => { 92 console.log("error.code = " + error.code) 93}) 94``` 95 96 97## startAbility 98 99startAbility(want: Want, options: StartOptions): Promise<void> 100 101Starts an ability with **options** specified. This API uses a promise to return the result. 102 103**System capability**: SystemCapability.Ability.AbilityRuntime.Core 104 105**Parameters** 106 107| Name| Type| Mandatory| Description| 108| -------- | -------- | -------- | -------- | 109| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 110| options | StartOptions | Yes| Parameters used for starting the ability.| 111 112**Return value** 113 114| Type| Description| 115| -------- | -------- | 116| Promise<void> | Promise used to return the result.| 117 118**Example** 119```js 120var want = { 121 "deviceId": "", 122 "bundleName": "com.extreme.test", 123 "abilityName": "com.extreme.test.MainAbility" 124}; 125var options = { 126 windowMode: 0, 127}; 128this.context.startAbility(want, options) 129.then(() => { 130 console.log('Operation successful.') 131}).catch((error) => { 132 console.log('Operation failed.'); 133}) 134``` 135 136## startAbilityByCall 137 138startAbilityByCall(want: Want): Promise<Caller> 139 140Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background. 141 142**System capability**: SystemCapability.Ability.AbilityRuntime.Core 143 144**Parameters** 145 146| Name| Type| Mandatory| Description| 147| -------- | -------- | -------- | -------- | 148| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.| 149 150**Return value** 151 152| Type| Description| 153| -------- | -------- | 154| Promise<Caller> | Promise used to return the caller object to communicate with.| 155 156**Example** 157 158```js 159import Ability from '@ohos.application.Ability'; 160var caller; 161export default class MainAbility extends Ability { 162 onWindowStageCreate(windowStage) { 163 this.context.startAbilityByCall({ 164 bundleName: "com.example.myservice", 165 abilityName: "com.example.myservice.MainAbility", 166 deviceId: "" 167 }).then((obj) => { 168 caller = obj; 169 console.log('Caller GetCaller Get ' + call); 170 }).catch((e) => { 171 console.log('Caller GetCaller error ' + e); 172 }); 173 } 174} 175``` 176 177## startAbilityWithAccount 178 179startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void 180 181Starts an ability with **accountId** specified. This API uses an asynchronous callback to return the result. 182 183**System capability**: SystemCapability.Ability.AbilityRuntime.Core 184 185**Parameters** 186 187| Name| Type| Mandatory| Description| 188| -------- | -------- | -------- | -------- | 189| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 190| accountId | number | Yes| Account ID. | 191| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 192 193**Example** 194 195```js 196var want = { 197 "deviceId": "", 198 "bundleName": "com.extreme.test", 199 "abilityName": "com.extreme.test.MainAbility" 200}; 201var accountId = 11; 202this.context.startAbility(want, accountId, (error) => { 203 console.log("error.code = " + error.code) 204}) 205``` 206 207## startAbilityWithAccount 208 209startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void>): void 210 211Starts an ability with **accountId** and **options** specified. This API uses an asynchronous callback to return the result. 212 213**System capability**: SystemCapability.Ability.AbilityRuntime.Core 214 215**Parameters** 216 217| Name| Type| Mandatory| Description| 218| -------- | -------- | -------- | -------- | 219| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 220| accountId | number | Yes| Account ID. | 221| options | StartOptions | Yes| Parameters used for starting the ability.| 222| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 223 224**Example** 225 226```js 227var want = { 228 "deviceId": "", 229 "bundleName": "com.extreme.test", 230 "abilityName": "com.extreme.test.MainAbility" 231}; 232var options = { 233 windowMode: 0, 234}; 235var accountId = 11; 236this.context.startAbility(want, accountId, options, (error) => { 237 console.log("error.code = " + error.code) 238}) 239``` 240 241 242## startAbilityWithAccount 243 244startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<void> 245 246Starts an ability with **accountId** and **options** specified. This API uses a promise to return the result. 247 248**System capability**: SystemCapability.Ability.AbilityRuntime.Core 249 250**Parameters** 251 252| Name| Type| Mandatory| Description| 253| -------- | -------- | -------- | -------- | 254| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 255| accountId | number | Yes| Account ID. | 256| options | StartOptions | No| Parameters used for starting the ability.| 257 258**Return value** 259 260| Type| Description| 261| -------- | -------- | 262| Promise<void> | Promise used to return the result.| 263 264**Example** 265```js 266var want = { 267 "deviceId": "", 268 "bundleName": "com.extreme.test", 269 "abilityName": "com.extreme.test.MainAbility" 270}; 271var options = { 272 windowMode: 0, 273}; 274var accountId = 11; 275this.context.startAbility(want, accountId, options) 276.then(() => { 277 console.log('Operation successful.') 278}).catch((error) => { 279 console.log('Operation failed.'); 280}) 281``` 282 283## startAbilityForResult 284 285startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void 286 287Starts an ability. This API uses an asynchronous callback to return the result when the ability is terminated. 288 289**System capability**: SystemCapability.Ability.AbilityRuntime.Core 290 291**Parameters** 292 293| Name| Type| Mandatory| Description| 294| -------- | -------- | -------- | -------- | 295| want |[Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 296| callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#AbilityResult)> | Yes| Callback used to return the result.| 297 298**Example** 299 300```js 301this.context.startAbilityForResult( 302 {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, 303 (error, result) => { 304 console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code) 305 console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode) 306 } 307); 308``` 309 310## startAbilityForResult 311 312startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void 313 314Starts an ability with **options** specified. This API uses an asynchronous callback to return the result when the ability is terminated. 315 316**System capability**: SystemCapability.Ability.AbilityRuntime.Core 317 318**Parameters** 319 320| Name| Type| Mandatory| Description| 321| -------- | -------- | -------- | -------- | 322| want |[Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 323| options | StartOptions | Yes| Parameters used for starting the ability.| 324| callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#AbilityResult)> | Yes| Callback used to return the result.| 325 326**Example** 327 328```js 329var options = { 330 windowMode: 0, 331}; 332this.context.startAbilityForResult( 333 {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options, 334 (error, result) => { 335 console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code) 336 console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode) 337 } 338); 339``` 340 341 342## startAbilityForResult 343 344startAbilityForResult(want: Want, options: StartOptions): Promise<AbilityResult>; 345 346Starts an ability with **options** specified. This API uses a promise to return the result when the ability is terminated. 347 348**System capability**: SystemCapability.Ability.AbilityRuntime.Core 349 350**Parameters** 351 352| Name| Type| Mandatory| Description| 353| -------- | -------- | -------- | -------- | 354| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 355| options | StartOptions | No | Parameters used for starting the ability.| 356 357**Return value** 358 359| Type| Description| 360| -------- | -------- | 361| Promise<[AbilityResult](js-apis-featureAbility.md#AbilityResult)> | Promise used to return the result.| 362 363**Example** 364```js 365var options = { 366 windowMode: 0, 367}; 368this.context.startAbilityForResult({bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options).then((result) => { 369 console.log("startAbilityForResult Promise.resolve is called, result.resultCode = " + result.resultCode) 370}, (error) => { 371 console.log("startAbilityForResult Promise.Reject is called, error.code = " + error.code) 372}) 373``` 374 375## startAbilityForResultWithAccount 376 377startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncCallback\<AbilityResult>): void 378 379Starts an ability with **accountId** specified. This API uses an asynchronous callback to return the result when the ability is terminated. 380 381**System capability**: SystemCapability.Ability.AbilityRuntime.Core 382 383**Parameters** 384 385| Name| Type| Mandatory| Description| 386| -------- | -------- | -------- | -------- | 387| want |[Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 388| accountId | number | Yes| Account ID. | 389| callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#AbilityResult)> | Yes| Callback used to return the result.| 390 391**Example** 392 393```js 394var accountId = 111; 395this.context.startAbilityForResult( 396 {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, 397 accountId, 398 (error, result) => { 399 console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code) 400 console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode) 401 } 402); 403``` 404 405## startAbilityForResultWithAccount 406 407startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void>): void 408 409Starts an ability with **accountId** and **options** specified. This API uses an asynchronous callback to return the result when the ability is terminated. 410 411**System capability**: SystemCapability.Ability.AbilityRuntime.Core 412 413**Parameters** 414 415| Name| Type| Mandatory| Description| 416| -------- | -------- | -------- | -------- | 417| want |[Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 418| accountId | number | Yes| Account ID. | 419| options | StartOptions | Yes| Parameters used for starting the ability.| 420| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 421 422**Example** 423 424```js 425var options = { 426 windowMode: 0, 427}; 428var accountId = 111; 429this.context.startAbilityForResult( 430 {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, 431 accountId, 432 options, 433 () => { 434 console.log("startAbilityForResult AsyncCallback is called") 435 } 436); 437``` 438 439## startAbilityForResultWithAccount 440 441startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<AbilityResult>; 442 443Starts an ability with **accountId** and **options** specified. This API uses a promise to return the result when the ability is terminated. 444 445**System capability**: SystemCapability.Ability.AbilityRuntime.Core 446 447**Parameters** 448 449| Name| Type| Mandatory| Description| 450| -------- | -------- | -------- | -------- | 451| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 452| accountId | number | Yes| Account ID. | 453| options | StartOptions | Yes| Parameters used for starting the ability.| 454 455**Return value** 456 457| Type| Description| 458| -------- | -------- | 459| Promise<[AbilityResult](js-apis-featureAbility.md#AbilityResult)> | Promise used to return the result.| 460 461**Example** 462 463```js 464var accountId = 111; 465var options = { 466 windowMode: 0, 467}; 468this.context.startAbilityForResult({bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, accountId, options).then((result) => { 469 console.log("startAbilityForResult Promise.resolve is called, result.resultCode = " + result.resultCode) 470}, (error) => { 471 console.log("startAbilityForResult Promise.Reject is called, error.code = " + error.code) 472}) 473``` 474 475## terminateSelf 476 477terminateSelf(callback: AsyncCallback<void>): void 478 479Terminates this ability. This API uses an asynchronous callback to return the result. 480 481**System capability**: SystemCapability.Ability.AbilityRuntime.Core 482 483**Parameters** 484 485| Name| Type| Mandatory| Description| 486| -------- | -------- | -------- | -------- | 487| callback | AsyncCallback<void> | Yes| Callback used to return the result indicating whether the API is successfully called.| 488 489**Example** 490 491```js 492this.context.terminateSelf((err) => { 493 console.log('terminateSelf result:' + JSON.stringify(err)); 494}); 495``` 496 497## terminateSelf 498 499terminateSelf(): Promise<void> 500 501Terminates this ability. This API uses a promise to return the result. 502 503**System capability**: SystemCapability.Ability.AbilityRuntime.Core 504 505**Return value** 506 507| Type| Description| 508| -------- | -------- | 509| Promise<void> | Promise used to return the result indicating whether the API is successfully called.| 510 511**Example** 512 513```js 514this.context.terminateSelf(want).then(() => { 515 console.log('success:'); 516}).catch((error) => { 517 console.log('failed:' + JSON.stringify(error)); 518}); 519``` 520 521## terminateSelfWithResult 522 523terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void 524 525Terminates this ability. This API uses an asynchronous callback to return the information to the caller of **startAbilityForResult**. 526 527**System capability**: SystemCapability.Ability.AbilityRuntime.Core 528 529**Parameters** 530 531| Name| Type| Mandatory| Description| 532| -------- | -------- | -------- | -------- | 533| parameter | [AbilityResult](js-apis-featureAbility.md#AbilityResult) | Yes| Information returned to the caller.| 534| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 535 536**Example** 537 538```js 539this.context.terminateSelfWithResult( 540 { 541 want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, 542 resultCode: 100 543 }, (error) => { 544 console.log("terminateSelfWithResult is called = " + error.code) 545 } 546); 547``` 548 549 550## terminateSelfWithResult 551 552terminateSelfWithResult(parameter: AbilityResult): Promise<void> 553 554Terminates this ability. This API uses a promise to return information to the caller of **startAbilityForResult**. 555 556**System capability**: SystemCapability.Ability.AbilityRuntime.Core 557 558**Parameters** 559| Name| Type| Mandatory| Description| 560| -------- | -------- | -------- | -------- | 561| parameter | [AbilityResult](js-apis-featureAbility.md#AbilityResult) | Yes| Information returned to the caller.| 562 563**Return value** 564| Type| Description| 565| -------- | -------- | 566| Promise<void> | Promise used to return the result.| 567 568**Example** 569```js 570this.context.terminateSelfWithResult( 571{ 572 want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, 573 resultCode: 100 574}).then(() => { 575 console.log("terminateSelfWithResult") 576}) 577``` 578 579## connectAbility 580 581connectAbility(want: Want, options: ConnectOptions): number 582 583Uses the **AbilityInfo.AbilityType.SERVICE** template to connect this ability to another ability. 584 585**System capability**: SystemCapability.Ability.AbilityRuntime.Core 586 587**Parameters** 588 589| Name| Type| Mandatory| Description| 590| -------- | -------- | -------- | -------- | 591| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 592| options | ConnectOptions | Yes| Connection channel.| 593 594**Return value** 595 596| Type| Description| 597| -------- | -------- | 598| number | Result code of the ability connection.| 599 600**Example** 601```js 602var want = { 603 "deviceId": "", 604 "bundleName": "com.extreme.test", 605 "abilityName": "com.extreme.test.MainAbility" 606} 607var options = { 608 onConnect: (elementName, remote) => { 609 console.log('connectAbility onConnect, elementName: ' + elementName + ', remote: ' + remote) 610 }, 611 onDisconnect: (elementName) => { 612 console.log('connectAbility onDisconnect, elementName: ' + elementName) 613 }, 614 onFailed: (code) => { 615 console.log('connectAbility onFailed, code: ' + code) 616 } 617} 618let result = this.context.connectAbility(want, options) { 619 console.log('code: ' + result) 620} 621``` 622 623## connectAbilityWithAccount 624 625connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number 626 627Uses the **AbilityInfo.AbilityType.SERVICE** template to connect this ability to another ability based on an account. 628 629**System capability**: SystemCapability.Ability.AbilityRuntime.Core 630 631**Parameters** 632 633| Name| Type| Mandatory| Description| 634| -------- | -------- | -------- | -------- | 635| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| 636| accountId | number | Yes| Account ID.| 637| options | ConnectOptions | Yes| Connection channel.| 638 639**Return value** 640 641| Type| Description| 642| -------- | -------- | 643| number | ID of the connection between the two abilities.| 644 645**Example** 646```js 647var want = { 648 "deviceId": "", 649 "bundleName": "com.extreme.test", 650 "abilityName": "com.extreme.test.MainAbility" 651} 652var accountId = 111; 653var options = { 654 onConnect: (elementName, remote) => { 655 console.log('connectAbility onConnect, elementName: ' + elementName + ', remote: ' + remote) 656 }, 657 onDisconnect: (elementName) => { 658 console.log('connectAbility onDisconnect, elementName: ' + elementName) 659 }, 660 onFailed: (code) => { 661 console.log('connectAbility onFailed, code: ' + code) 662 } 663} 664this.context.connectAbility(want, accountId, options) { 665 console.log('code: ' + code) 666} 667``` 668 669## disconnectAbility 670 671disconnectAbility(connection: number, callback:AsyncCallback\<void>): void 672 673Disconnects this ability from another ability. This API uses an asynchronous callback to return the result. 674 675**System capability**: SystemCapability.Ability.AbilityRuntime.Core 676 677**Parameters** 678 679| Name| Type| Mandatory| Description| 680| -------- | -------- | -------- | -------- | 681| connection | number | Yes| ID of the connection to be disconnected.| 682| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 683 684**Example** 685 686```js 687var connection = 111; 688this.context.disconnectAbility(connection, () => { 689 console.log('disconnection') 690}) 691``` 692 693## disconnectAbility 694 695disconnectAbility(connection: number): Promise\<void> 696 697Disconnects this ability from another ability. This API uses a promise to return the result. 698 699**System capability**: SystemCapability.Ability.AbilityRuntime.Core 700 701**Parameters** 702 703| Name| Type| Mandatory| Description| 704| -------- | -------- | -------- | -------- | 705| connection | number | Yes| ID of the connection to be disconnected.| 706 707**Return value** 708 709| Type| Description| 710| -------- | -------- | 711| Promise<void> | Promise used to return the result.| 712 713**Example** 714 715```js 716var connection = 111; 717this.context.disconnectAbility(connection).then(() => { 718 console.log('disconnect success') 719}).catch((err) => { 720 console.log('disconnect failed') 721}) 722``` 723 724## setMissionLabel 725 726setMissionLabel(label: string, callback:AsyncCallback<void>): void 727 728Sets the label of the ability in the mission. This API uses an asynchronous callback to return the result. 729 730**System capability**: SystemCapability.Ability.AbilityRuntime.Core 731 732**Parameters** 733 734| Name| Type| Mandatory| Description| 735| -------- | -------- | -------- | -------- | 736| label | string | Yes| Label of the ability to set.| 737| callback | AsyncCallback<void> | Yes| Callback used to return the result indicating whether the API is successfully called.| 738 739**Example** 740 741```js 742this.context.setMissionLabel("test",(result) => { 743 console.log('requestPermissionsFromUserresult:' + JSON.stringify(result)); 744}); 745``` 746 747 748## setMissionLabel 749 750setMissionLabel(label: string): Promise\<void> 751 752Sets the label of the ability in the mission. This API uses a promise to return the result. 753 754**System capability**: SystemCapability.Ability.AbilityRuntime.Core 755 756**Parameters** 757 758| Name| Type| Mandatory| Description| 759| -------- | -------- | -------- | -------- | 760| label | string | Yes| Label of the ability to set.| 761 762**Return value** 763 764| Type| Description| 765| -------- | -------- | 766| Promise<void> | Promise used to return the result indicating whether the API is successfully called.| 767 768**Example** 769 770```js 771this.context.setMissionLabel("test").then(() => { 772 console.log('success:'); 773}).catch((error) => { 774 console.log('failed:' + JSON.stringify(error)); 775}); 776``` 777 778## requestPermissionsFromUser 779 780requestPermissionsFromUser(permissions: Array<string>, requestCallback: AsyncCallback<PermissionRequestResult>) : void 781 782Requests permissions from end users in the form of a dialog box. This API uses an asynchronous callback to return the result. 783 784**System capability**: SystemCapability.Ability.AbilityRuntime.Core 785 786**Parameters** 787 788| Name| Type| Mandatory| Description| 789| -------- | -------- | -------- | -------- | 790| permissions | Array<string> | Yes| Permissions to request.| 791| callback | AsyncCallback<PermissionRequestResult> | Yes| Callback used to return the result indicating whether the API is successfully called.| 792 793**Example** 794 795```js 796this.context.requestPermissionsFromUser(permissions,(result) => { 797 console.log('requestPermissionsFromUserresult:' + JSON.stringify(result)); 798}); 799``` 800 801 802## requestPermissionsFromUser 803 804requestPermissionsFromUser(permissions: Array<string>) : Promise<PermissionRequestResult> 805 806Requests permissions from end users in the form of a dialog box. This API uses a promise to return the result. 807 808**System capability**: SystemCapability.Ability.AbilityRuntime.Core 809 810**Parameters** 811 812| Name| Type| Mandatory| Description| 813| -------- | -------- | -------- | -------- | 814| permissions | Array<string> | Yes| Permissions to request.| 815 816**Return value** 817 818| Type| Description| 819| -------- | -------- | 820| Promise<PermissionRequestResult> | Promise used to return the result indicating whether the API is successfully called.| 821 822**Example** 823 824```js 825this.context.requestPermissionsFromUser(permissions).then((data) => { 826 console.log('success:' + JSON.stringify(data)); 827}).catch((error) => { 828 console.log('failed:' + JSON.stringify(error)); 829}); 830``` 831 832## restoreWindowStage 833 834restoreWindowStage(contentStorage: ContentStorage) : void 835 836Restores the window stage data during ability continuation. 837 838**System capability**: SystemCapability.Ability.AbilityRuntime.Core 839 840**Parameters** 841 842| Name| Type| Mandatory| Description| 843| -------- | -------- | -------- | -------- | 844| contentStorage | ContentStorage | Yes| Window stage data to restore.| 845 846**Example** 847 848```js 849var contentStorage = { 850 "link": 'link', 851}; 852this.context.restoreWindowStage(contentStorage); 853``` 854