1# Context 2 3The **Context** module provides context for abilities or applications. It allows access to application-specific resources, as well as permission requests and verification. 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## Usage 12 13The **Context** object is created in a **featureAbility** and returned through its [getContext](js-apis-ability-featureAbility.md#featureabilitygetcontext) API. Therefore, you must import the **@ohos.ability.featureAbility** package before using the **Context** module. An example is as follows: 14 15```ts 16import featureAbility from '@ohos.ability.featureAbility'; 17let context = featureAbility.getContext(); 18context.getOrCreateLocalDir().then((data) => { 19 console.info('getOrCreateLocalDir data: ' + JSON.stringify(data)); 20}); 21``` 22 23## Context.getOrCreateLocalDir<sup>7+</sup> 24 25getOrCreateLocalDir(callback: AsyncCallback\<string>): void 26 27Obtains the local root directory of the application. This API uses an asynchronous callback to return the result. 28 29If this API is called for the first time, a root directory will be created. 30 31**System capability**: SystemCapability.Ability.AbilityRuntime.Core 32 33**Parameters** 34 35| Name | Type | Mandatory | Description | 36| -------- | ---------------------- | ---- | ------------- | 37| callback | AsyncCallback\<string> | Yes | Callback used to return the local root directory.| 38 39**Example** 40 41```ts 42import featureAbility from '@ohos.ability.featureAbility'; 43let context = featureAbility.getContext(); 44context.getOrCreateLocalDir((err, data)=>{ 45 console.info('getOrCreateLocalDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 46}); 47``` 48 49 50 51## Context.getOrCreateLocalDir<sup>7+</sup> 52 53getOrCreateLocalDir(): Promise\<string> 54 55Obtains the local root directory of the application. This API uses a promise to return the result. 56 57If this API is called for the first time, a root directory will be created. 58 59**System capability**: SystemCapability.Ability.AbilityRuntime.Core 60 61**Return value** 62 63| Type | Description | 64| ---------------- | ----------- | 65| Promise\<string> | Promise used to return the local root directory.| 66 67**Example** 68 69```ts 70import featureAbility from '@ohos.ability.featureAbility'; 71let context = featureAbility.getContext(); 72context.getOrCreateLocalDir().then((data) => { 73 console.info('getOrCreateLocalDir data: ' + JSON.stringify(data)); 74}); 75``` 76 77## Context.verifyPermission<sup>7+</sup> 78 79verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\<number>): void 80 81Verifies whether a specific PID and UID have the given permission. This API uses an asynchronous callback to return the result. 82 83**System capability**: SystemCapability.Ability.AbilityRuntime.Core 84 85**Parameters** 86 87| Name | Type | Mandatory | Description | 88| ---------- | --------------------------------------- | ---- | -------------------- | 89| permission | string | Yes | Name of the permission to verify. | 90| options | [PermissionOptions](#permissionoptions7) | Yes | Permission options. | 91| callback | AsyncCallback\<number> | Yes | Callback used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.| 92 93**Example** 94 95```ts 96import featureAbility from '@ohos.ability.featureAbility'; 97import bundle from '@ohos.bundle'; 98let context = featureAbility.getContext(); 99bundle.getBundleInfo('com.context.test', 1, (err, datainfo) =>{ 100 context.verifyPermission('com.example.permission', {uid:datainfo.uid}, (err, data) =>{ 101 console.info('verifyPermission err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 102 }); 103}); 104``` 105 106 107 108## Context.verifyPermission<sup>7+</sup> 109 110verifyPermission(permission: string, callback: AsyncCallback\<number>): void 111 112Verifies whether the current PID and UID have the given permission. This API uses an asynchronous callback to return the result. 113 114**System capability**: SystemCapability.Ability.AbilityRuntime.Core 115 116**Parameters** 117 118| Name | Type | Mandatory | Description | 119| ---------- | ---------------------- | ---- | -------------------- | 120| permission | string | Yes | Name of the permission to verify. | 121| callback | AsyncCallback\<number> | Yes | Callback used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.| 122 123**Example** 124 125```ts 126import featureAbility from '@ohos.ability.featureAbility'; 127let context = featureAbility.getContext(); 128context.verifyPermission('com.example.permission', (err, data) =>{ 129 console.info('verifyPermission err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 130}); 131``` 132 133## Context.verifyPermission<sup>7+</sup> 134 135verifyPermission(permission: string, options?: PermissionOptions): Promise\<number> 136 137Verifies whether a specific PID and UID have the given permission. This API uses a promise to return the result. 138 139**System capability**: SystemCapability.Ability.AbilityRuntime.Core 140 141**Parameters** 142 143| Name | Type | Mandatory | Description | 144| ---------- | --------------------------------------- | ---- | -------- | 145| permission | string | Yes | Name of the permission to verify.| 146| options | [PermissionOptions](#permissionoptions) | No | Permission options. | 147 148**Return value** 149 150| Type | Description | 151| ---------------- | ---------------------------------- | 152| Promise\<number> | Promise used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.| 153 154**Example** 155 156```ts 157import featureAbility from '@ohos.ability.featureAbility'; 158let context = featureAbility.getContext(); 159let Permission = {pid:1}; 160context.verifyPermission('com.context.permission',Permission).then((data) => { 161 console.info('verifyPermission data: ' + JSON.stringify(data)); 162}); 163``` 164 165 166 167## Context.requestPermissionsFromUser<sup>7+</sup> 168 169requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#permissionrequestresult)>): void 170 171Requests certain permissions from the system. This API uses an asynchronous callback to return the result. 172 173**System capability**: SystemCapability.Ability.AbilityRuntime.Core 174 175**Parameters** 176 177| Name | Type | Mandatory | Description | 178| -------------- | ---------------------------------------- | ---- | ----------------------------------- | 179| permissions | Array\<string> | Yes | Permissions to request. This parameter cannot be **null**. | 180| requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.| 181| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Callback used to return the permission request result. | 182 183**Example** 184 185```ts 186import featureAbility from '@ohos.ability.featureAbility'; 187let context = featureAbility.getContext(); 188context.requestPermissionsFromUser( 189 ['com.example.permission1', 190 'com.example.permission2', 191 'com.example.permission3', 192 'com.example.permission4', 193 'com.example.permission5'], 194 1, 195 (err, data) => { 196 console.info('requestPermissionsFromUser err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 197 } 198); 199``` 200 201 202## Context.requestPermissionsFromUser<sup>7+</sup> 203 204requestPermissionsFromUser(permissions: Array\<string>, requestCode: number): Promise\<[PermissionRequestResult](#permissionrequestresult7)> 205 206Requests certain permissions from the system. This API uses a promise to return the result. 207 208**System capability**: SystemCapability.Ability.AbilityRuntime.Core 209 210**Parameters** 211 212| Name | Type | Mandatory | Description | 213| -------------- | ------------------- | ----- | -------------------------------------------- | 214| permissions | Array\<string> | Yes | Permissions to request. This parameter cannot be **null**. | 215| requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.| 216 217**Return value** 218 219| Type | Description | 220| ------------------------------------------------------------- | ---------------- | 221| Promise\<[PermissionRequestResult](#permissionrequestresult7)> | Promise used to return the permission request result.| 222 223**Example** 224 225```ts 226import featureAbility from '@ohos.ability.featureAbility'; 227let context = featureAbility.getContext(); 228context.requestPermissionsFromUser( 229 ['com.example.permission1', 230 'com.example.permission2', 231 'com.example.permission3', 232 'com.example.permission4', 233 'com.example.permission5'], 234 1).then((data)=>{ 235 console.info('requestPermissionsFromUser data: ' + JSON.stringify(data)); 236 } 237); 238``` 239 240 241 242## Context.getApplicationInfo<sup>7+</sup> 243 244getApplicationInfo(callback: AsyncCallback\<ApplicationInfo>): void 245 246Obtains information about the current application. This API uses an asynchronous callback to return the result. 247 248**System capability**: SystemCapability.Ability.AbilityRuntime.Core 249 250**Parameters** 251 252| Name | Type | Mandatory | Description | 253| -------- | ------------------------------- | ---- | ------------ | 254| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)> | Yes | Callback used to return the application information.| 255 256**Example** 257 258```ts 259import featureAbility from '@ohos.ability.featureAbility'; 260let context = featureAbility.getContext(); 261context.getApplicationInfo((err, data) => { 262 console.info('getApplicationInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 263}); 264``` 265 266 267 268## Context.getApplicationInfo<sup>7+</sup> 269 270getApplicationInfo(): Promise\<ApplicationInfo> 271 272Obtains information about the current application. This API uses a promise to return the result. 273 274**System capability**: SystemCapability.Ability.AbilityRuntime.Core 275 276**Return value** 277 278| Type | Description | 279| ------------------------- | --------- | 280| Promise\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)> | Promise used to return the application information.| 281 282**Example** 283 284```ts 285import featureAbility from '@ohos.ability.featureAbility'; 286let context = featureAbility.getContext(); 287context.getApplicationInfo().then((data) => { 288 console.info('getApplicationInfo data: ' + JSON.stringify(data)); 289}); 290``` 291 292 293 294## Context.getBundleName<sup>7+</sup> 295 296getBundleName(callback: AsyncCallback\<string>): void 297 298Obtains the bundle name of this ability. This API uses an asynchronous callback to return the result. 299 300**System capability**: SystemCapability.Ability.AbilityRuntime.Core 301 302**Parameters** 303 304| Name | Type | Mandatory | Description | 305| -------- | ---------------------- | ---- | ------------------ | 306| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.| 307 308**Example** 309 310```ts 311import featureAbility from '@ohos.ability.featureAbility'; 312let context = featureAbility.getContext(); 313context.getBundleName((err, data) => { 314 console.info('getBundleName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 315}); 316``` 317 318 319 320## Context.getBundleName<sup>7+</sup> 321 322getBundleName(): Promise\<string> 323 324Obtains the bundle name of this ability. This API uses a promise to return the result. 325 326**System capability**: SystemCapability.Ability.AbilityRuntime.Core 327 328**Return value** 329 330| Type | Description | 331| ---------------- | ---------------- | 332| Promise\<string> | Promise used to return the bundle name.| 333 334**Example** 335 336```ts 337import featureAbility from '@ohos.ability.featureAbility'; 338let context = featureAbility.getContext(); 339context.getBundleName().then((data) => { 340 console.info('getBundleName data: ' + JSON.stringify(data)); 341}); 342``` 343 344## Context.getDisplayOrientation<sup>7+</sup> 345 346getDisplayOrientation(callback: AsyncCallback\<bundle.DisplayOrientation>): void 347 348Obtains the display orientation of this ability. This API uses an asynchronous callback to return the result. 349 350**System capability**: SystemCapability.Ability.AbilityRuntime.Core 351 352**Parameters** 353 354| Name | Type | Mandatory| Description | 355| -------- | ------------------------------------------------------------ | ---- | ------------------ | 356| callback | AsyncCallback\<[bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation)> | Yes | Callback used to return the display orientation.| 357 358**Example** 359 360```ts 361import featureAbility from '@ohos.ability.featureAbility'; 362let context = featureAbility.getContext(); 363context.getDisplayOrientation((err, data) => { 364 console.info('getDisplayOrientation err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 365}); 366``` 367 368## Context.getDisplayOrientation<sup>7+</sup> 369 370getDisplayOrientation(): Promise\<bundle.DisplayOrientation>; 371 372Obtains the display orientation of this ability. This API uses a promise to return the result. 373 374**System capability**: SystemCapability.Ability.AbilityRuntime.Core 375 376**Return value** 377 378| Type | Description | 379| ---------------------------------------- | --------- | 380| Promise\<[bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation)> | Promise used to return the display orientation.| 381 382**Example** 383 384```ts 385import featureAbility from '@ohos.ability.featureAbility'; 386let context = featureAbility.getContext(); 387context.getDisplayOrientation().then((data) => { 388 console.info('getDisplayOrientation data: ' + JSON.stringify(data)); 389}); 390``` 391 392## Context.getExternalCacheDir 393 394getExternalCacheDir(callback: AsyncCallback\<string>): void 395 396Obtains the external cache directory of the application. This API uses an asynchronous callback to return the result. 397 398**System capability**: SystemCapability.Ability.AbilityRuntime.Core 399 400**Parameters** 401 402| Name | Type | Mandatory | Description | 403| -------- | ---------------------- | ---- | ------------------ | 404| callback | AsyncCallback\<string> | Yes | Callback used to return the absolute path of the cache directory.| 405 406**Example** 407 408```ts 409import featureAbility from '@ohos.ability.featureAbility'; 410let context = featureAbility.getContext(); 411context.getExternalCacheDir((err, data) => { 412 console.info('getExternalCacheDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 413}); 414``` 415 416## Context.getExternalCacheDir 417 418getExternalCacheDir(): Promise\<string>; 419 420Obtains the external cache directory of the application. This API uses a promise to return the result. 421 422**System capability**: SystemCapability.Ability.AbilityRuntime.Core 423 424**Return value** 425 426| Type | Description | 427| ---------------- | ---------------- | 428| Promise\<string> | Promise used to return the absolute path of the cache directory.| 429 430**Example** 431 432```ts 433import featureAbility from '@ohos.ability.featureAbility'; 434let context = featureAbility.getContext(); 435context.getExternalCacheDir().then((data) => { 436 console.info('getExternalCacheDir data: ' + JSON.stringify(data)); 437}); 438``` 439 440## Context.setDisplayOrientation<sup>7+</sup> 441 442setDisplayOrientation(orientation: bundle.DisplayOrientation, callback: AsyncCallback\<void>): void 443 444Sets the display orientation for this ability. This API uses an asynchronous callback to return the result. 445 446**System capability**: SystemCapability.Ability.AbilityRuntime.Core 447 448**Parameters** 449 450| Name | Type | Mandatory | Description | 451| ----------- | ---------------------------------------- | ---- | ------------ | 452| orientation | [bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation) | Yes | Display orientation to set.| 453| callback | AsyncCallback\<void> | Yes | Callback used to return the display orientation. | 454 455**Example** 456 457```ts 458import featureAbility from '@ohos.ability.featureAbility'; 459import bundle from '@ohos.bundle'; 460let context = featureAbility.getContext(); 461let orientation=bundle.DisplayOrientation.UNSPECIFIED 462context.setDisplayOrientation(orientation, (err) => { 463 console.info('setDisplayOrientation err: ' + JSON.stringify(err)); 464}); 465``` 466 467## Context.setDisplayOrientation<sup>7+</sup> 468 469setDisplayOrientation(orientation: bundle.DisplayOrientation): Promise\<void>; 470 471Sets the display orientation for this ability. This API uses a promise to return the result. 472 473**System capability**: SystemCapability.Ability.AbilityRuntime.Core 474 475**Return value** 476 477| Type | Description | 478| ---------------------------------------- | ---------------------------------------- | 479| orientation | [bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation) | 480| Promise\<void> | Promise used to return the display orientation. | 481 482**Example** 483 484```ts 485import featureAbility from '@ohos.ability.featureAbility'; 486import bundle from '@ohos.bundle'; 487let context = featureAbility.getContext(); 488let orientation=bundle.DisplayOrientation.UNSPECIFIED 489context.setDisplayOrientation(orientation).then((data) => { 490 console.info('setDisplayOrientation data: ' + JSON.stringify(data)); 491}); 492``` 493 494## Context.setShowOnLockScreen<sup>7+</sup> 495 496setShowOnLockScreen(show: boolean, callback: AsyncCallback\<void>): void 497 498Sets whether to show this feature at the top of the lock screen so that the feature remains activated. This API uses an asynchronous callback to return the result. 499 500**System capability**: SystemCapability.Ability.AbilityRuntime.Core 501 502**Parameters** 503 504| Name | Type | Mandatory | Description | 505| -------- | -------------------- | ---- | ---------------------------------------- | 506| show | boolean | Yes | Whether to show this feature at the top of the lock screen. The value **true** means to show this feature at the top of the lock screen, and **false** means the opposite.| 507| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 508 509**Example** 510 511```ts 512import featureAbility from '@ohos.ability.featureAbility'; 513let context = featureAbility.getContext(); 514let show=true 515context.setShowOnLockScreen(show, (err) => { 516 console.info('setShowOnLockScreen err: ' + JSON.stringify(err)); 517}); 518``` 519 520## Context.setShowOnLockScreen<sup>7+</sup> 521 522setShowOnLockScreen(show: boolean): Promise\<void>; 523 524Sets whether to show this feature at the top of the lock screen so that the feature remains activated. This API uses a promise to return the result. 525 526**System capability**: SystemCapability.Ability.AbilityRuntime.Core 527 528**Parameters** 529 530| Name | Type | Mandatory | Description | 531| ---- | ------- | ---- | ---------------------------------------- | 532| show | boolean | Yes | Whether to show this feature at the top of the lock screen. The value **true** means to show this feature at the top of the lock screen, and **false** means the opposite.| 533 534**Return value** 535 536| Type | Description | 537| -------------- | --------------- | 538| Promise\<void> | Promise used to return the result.| 539 540**Example** 541 542```ts 543import featureAbility from '@ohos.ability.featureAbility'; 544let context = featureAbility.getContext(); 545let show=true 546context.setShowOnLockScreen(show).then((data) => { 547 console.info('setShowOnLockScreen data: ' + JSON.stringify(data)); 548}); 549``` 550 551## Context.setWakeUpScreen<sup>7+</sup> 552 553setWakeUpScreen(wakeUp: boolean, callback: AsyncCallback\<void>): void 554 555Sets whether to wake up the screen when this feature is restored. This API uses an asynchronous callback to return the result. 556 557**System capability**: SystemCapability.Ability.AbilityRuntime.Core 558 559**Parameters** 560 561| Name | Type | Mandatory | Description | 562| -------- | -------------------- | ---- | --------------------------------- | 563| wakeUp | boolean | Yes | Whether to wake up the screen. The value **true** means to wake up the screen, and **false** means the opposite.| 564| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 565 566**Example** 567 568```ts 569import featureAbility from '@ohos.ability.featureAbility'; 570let context = featureAbility.getContext(); 571let wakeUp=true 572context.setWakeUpScreen(wakeUp, (err) => { 573 console.info('setWakeUpScreen err: ' + JSON.stringify(err)); 574}); 575``` 576 577## Context.setWakeUpScreen<sup>7+</sup> 578 579setWakeUpScreen(wakeUp: boolean): Promise\<void>; 580 581Sets whether to wake up the screen when this feature is restored. This API uses a promise to return the result. 582 583**System capability**: SystemCapability.Ability.AbilityRuntime.Core 584 585**Parameters** 586 587| Name | Type | Mandatory | Description | 588| ------ | ------- | ---- | --------------------------------- | 589| wakeUp | boolean | Yes | Whether to wake up the screen. The value **true** means to wake up the screen, and **false** means the opposite.| 590 591**Return value** 592 593| Type | Description | 594| -------------- | --------------- | 595| Promise\<void> | Promise used to return the result.| 596 597**Example** 598 599```ts 600import featureAbility from '@ohos.ability.featureAbility'; 601let context = featureAbility.getContext(); 602let wakeUp=true 603context.setWakeUpScreen(wakeUp).then((data) => { 604 console.info('setWakeUpScreen data: ' + JSON.stringify(data)); 605}); 606``` 607 608 609 610 611## Context.getProcessInfo<sup>7+</sup> 612 613getProcessInfo(callback: AsyncCallback\<ProcessInfo>): void 614 615Obtains information about the current process, including the PID and process name. This API uses an asynchronous callback to return the result. 616 617**System capability**: SystemCapability.Ability.AbilityRuntime.Core 618 619**Parameters** 620 621| Name | Type | Mandatory | Description | 622| -------- | --------------------------- | ---- | ---------- | 623| callback | AsyncCallback\<[ProcessInfo](js-apis-inner-app-processInfo.md)> | Yes | Callback used to return the process information.| 624 625**Example** 626 627```ts 628import featureAbility from '@ohos.ability.featureAbility'; 629let context = featureAbility.getContext(); 630context.getProcessInfo((err, data) => { 631 console.info('getProcessInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 632}); 633``` 634 635 636 637## Context.getProcessInfo<sup>7+</sup> 638 639getProcessInfo(): Promise\<ProcessInfo> 640 641Obtains information about the current process, including the PID and process name. This API uses a promise to return the result. 642 643**System capability**: SystemCapability.Ability.AbilityRuntime.Core 644 645**Return value** 646 647| Type | Description | 648| --------------------- | ------- | 649| Promise\<[ProcessInfo](js-apis-inner-app-processInfo.md)> | Promise used to return the process information.| 650 651**Example** 652 653```ts 654import featureAbility from '@ohos.ability.featureAbility'; 655let context = featureAbility.getContext(); 656context.getProcessInfo().then((data) => { 657 console.info('getProcessInfo data: ' + JSON.stringify(data)); 658}); 659``` 660 661 662 663## Context.getElementName<sup>7+</sup> 664 665getElementName(callback: AsyncCallback\<ElementName>): void 666 667Obtains the **ohos.bundle.ElementName** object of this ability. This API uses an asynchronous callback to return the result. 668 669This API is available only to Page abilities. 670 671**System capability**: SystemCapability.Ability.AbilityRuntime.Core 672 673**Parameters** 674 675| Name | Type | Mandatory | Description | 676| -------- | --------------------------- | ---- | -------------------------------------- | 677| callback | AsyncCallback\<[ElementName](js-apis-bundle-ElementName.md)> | Yes | Callback used to return the **ohos.bundle.ElementName** object.| 678 679**Example** 680 681```ts 682import featureAbility from '@ohos.ability.featureAbility'; 683let context = featureAbility.getContext(); 684context.getElementName((err, data) => { 685 console.info('getElementName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 686}); 687``` 688 689 690 691## Context.getElementName<sup>7+</sup> 692 693getElementName(): Promise\<ElementName> 694 695Obtains the **ohos.bundle.ElementName** object of this ability. This API uses a promise to return the result. 696 697This API is available only to Page abilities. 698 699**System capability**: SystemCapability.Ability.AbilityRuntime.Core 700 701**Return value** 702 703| Type | Description | 704| --------------------- | ------------------------------------ | 705| Promise\<[ElementName](js-apis-bundle-ElementName.md)> | Promise used to return the **ohos.bundle.ElementName** object.| 706 707**Example** 708 709```ts 710import featureAbility from '@ohos.ability.featureAbility'; 711let context = featureAbility.getContext(); 712context.getElementName().then((data) => { 713 console.info('getElementName data: ' + JSON.stringify(data)); 714}); 715``` 716 717## Context.getProcessName<sup>7+</sup> 718 719getProcessName(callback: AsyncCallback\<string>): void 720 721Obtains the name of the current process. This API uses an asynchronous callback to return the result. 722 723**System capability**: SystemCapability.Ability.AbilityRuntime.Core 724 725**Parameters** 726 727| Name | Type | Mandatory | Description | 728| -------- | ---------------------- | ---- | ---------- | 729| callback | AsyncCallback\<string> | Yes | Callback used to return the process name.| 730 731**Example** 732 733```ts 734import featureAbility from '@ohos.ability.featureAbility'; 735let context = featureAbility.getContext(); 736context.getProcessName((err, data) => { 737 console.info('getProcessName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 738}); 739``` 740 741 742 743## Context.getProcessName<sup>7+</sup> 744 745getProcessName(): Promise\<string> 746 747Obtains the name of the current process. This API uses a promise to return the result. 748 749**System capability**: SystemCapability.Ability.AbilityRuntime.Core 750 751**Return value** 752 753| Type | Description | 754| ---------------- | ---------- | 755| Promise\<string> | Promise used to return the process name.| 756 757**Example** 758 759```ts 760import featureAbility from '@ohos.ability.featureAbility'; 761let context = featureAbility.getContext(); 762context.getProcessName().then((data) => { 763 console.info('getProcessName data: ' + JSON.stringify(data)); 764}); 765``` 766 767 768 769## Context.getCallingBundle<sup>7+</sup> 770 771getCallingBundle(callback: AsyncCallback\<string>): void 772 773Obtains the bundle name of the caller ability. This API uses an asynchronous callback to return the result. 774 775**System capability**: SystemCapability.Ability.AbilityRuntime.Core 776 777**Parameters** 778 779| Name | Type | Mandatory | Description | 780| -------- | ---------------------- | ---- | ---------------- | 781| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.| 782 783**Example** 784 785```ts 786import featureAbility from '@ohos.ability.featureAbility'; 787let context = featureAbility.getContext(); 788context.getCallingBundle((err, data) => { 789 console.info('getCallingBundle err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 790}); 791``` 792 793 794 795## Context.getCallingBundle<sup>7+</sup> 796 797getCallingBundle(): Promise\<string> 798 799Obtains the bundle name of the caller ability. This API uses a promise to return the result. 800 801**System capability**: SystemCapability.Ability.AbilityRuntime.Core 802 803**Return value** 804 805| Type | Description | 806| ---------------- | -------------- | 807| Promise\<string> | Promise used to return the bundle name.| 808 809**Example** 810 811```ts 812import featureAbility from '@ohos.ability.featureAbility'; 813let context = featureAbility.getContext(); 814context.getCallingBundle().then((data) => { 815 console.info('getCallingBundle data: ' + JSON.stringify(data)); 816}); 817``` 818 819## Context.getCacheDir 820 821getCacheDir(callback: AsyncCallback\<string>): void 822 823Obtains the cache directory of the application in the internal storage. This API uses an asynchronous callback to return the result. 824 825**System capability**: SystemCapability.Ability.AbilityRuntime.Core 826 827**Parameters** 828 829| Name | Type | Mandatory | Description | 830| -------- | ---------------------- | ---- | --------------- | 831| callback | AsyncCallback\<string> | Yes | Callback used to return the cache directory.| 832 833**Example** 834 835```ts 836import featureAbility from '@ohos.ability.featureAbility'; 837let context = featureAbility.getContext(); 838context.getCacheDir((err, data) => { 839 console.info('getCacheDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 840}); 841``` 842 843## Context.getCacheDir 844 845getCacheDir(): Promise\<string> 846 847Obtains the cache directory of the application in the internal storage. This API uses a promise to return the result. 848 849**System capability**: SystemCapability.Ability.AbilityRuntime.Core 850 851**Return value** 852 853| Type | Description | 854| ---------------- | --------------- | 855| Promise\<string> | Promise used to return the cache directory.| 856 857**Example** 858 859```ts 860import featureAbility from '@ohos.ability.featureAbility'; 861let context = featureAbility.getContext(); 862context.getCacheDir().then((data) => { 863 console.info('getCacheDir data: ' + JSON.stringify(data)); 864}); 865``` 866 867## Context.getFilesDir 868 869getFilesDir(callback: AsyncCallback\<string>): void 870 871Obtains the file directory of the application in the internal storage. This API uses an asynchronous callback to return the result. 872 873**System capability**: SystemCapability.Ability.AbilityRuntime.Core 874 875**Parameters** 876 877| Name | Type | Mandatory | Description | 878| -------- | ---------------------- | ---- | ------------------- | 879| callback | AsyncCallback\<string> | Yes | Callback used to return the file directory.| 880 881**Example** 882 883```ts 884import featureAbility from '@ohos.ability.featureAbility'; 885let context = featureAbility.getContext(); 886context.getFilesDir((err, data) => { 887 console.info('getFilesDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 888}); 889``` 890 891## Context.getFilesDir 892 893getFilesDir(): Promise\<string> 894 895Obtains the file directory of the application in the internal storage. This API uses a promise to return the result. 896 897**System capability**: SystemCapability.Ability.AbilityRuntime.Core 898 899**Return value** 900 901| Type | Description | 902| ---------------- | ------------------- | 903| Promise\<string> | Promise used to return the file directory.| 904 905**Example** 906 907```ts 908import featureAbility from '@ohos.ability.featureAbility'; 909let context = featureAbility.getContext(); 910context.getFilesDir().then((data) => { 911 console.info('getFilesDir data: ' + JSON.stringify(data)); 912}); 913``` 914 915## Context.getOrCreateDistributedDir<sup>7+</sup> 916 917getOrCreateDistributedDir(callback: AsyncCallback\<string>): void 918 919Obtains the distributed file path for storing ability or application data files. This API uses an asynchronous callback to return the result. 920 921If the distributed file path does not exist, the system will create one and return the created path. 922 923**System capability**: SystemCapability.Ability.AbilityRuntime.Core 924 925**Parameters** 926 927| Name | Type | Mandatory | Description | 928| -------- | ---------------------- | ---- | ---------------------------------------- | 929| callback | AsyncCallback\<string> | Yes | Callback used to return the distributed file path.<br>If the path does not exist, the system will create one and return the created path.| 930 931**Example** 932 933```ts 934import featureAbility from '@ohos.ability.featureAbility'; 935let context = featureAbility.getContext(); 936context.getOrCreateDistributedDir((err, data) => { 937 console.info('getOrCreateDistributedDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 938}); 939``` 940 941## Context.getOrCreateDistributedDir<sup>7+</sup> 942 943getOrCreateDistributedDir(): Promise\<string> 944 945Obtains the distributed file path for storing ability or application data files. This API uses a promise to return the result. 946 947If the distributed file path does not exist, the system will create one and return the created path. 948 949**System capability**: SystemCapability.Ability.AbilityRuntime.Core 950 951**Return value** 952 953| Type | Description | 954| ---------------- | ----------------------------------- | 955| Promise\<string> | Promise used to return the distributed file path. If this API is called for the first time, a path will be created.| 956 957**Example** 958 959```ts 960import featureAbility from '@ohos.ability.featureAbility'; 961let context = featureAbility.getContext(); 962context.getOrCreateDistributedDir().then((data) => { 963 console.info('getOrCreateDistributedDir data: ' + JSON.stringify(data)); 964}); 965``` 966 967## Context.getAppType<sup>7+</sup> 968 969getAppType(callback: AsyncCallback\<string>): void 970 971Obtains the application type. This API uses an asynchronous callback to return the result. 972 973**System capability**: SystemCapability.Ability.AbilityRuntime.Core 974 975**Parameters** 976 977| Name | Type | Mandatory | Description | 978| -------- | ---------------------- | ---- | -------------------------------- | 979| callback | AsyncCallback\<string> | Yes | Callback used to return the application type.| 980 981**Example** 982 983```ts 984import featureAbility from '@ohos.ability.featureAbility'; 985let context = featureAbility.getContext(); 986context.getAppType((err, data) => { 987 console.info('getAppType err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 988}); 989``` 990 991## Context.getAppType<sup>7+</sup> 992 993getAppType(): Promise\<string> 994 995Obtains the application type. This API uses a promise to return the result. 996 997**System capability**: SystemCapability.Ability.AbilityRuntime.Core 998 999**Return value** 1000 1001| Type | Description | 1002| ---------------- | ------------------ | 1003| Promise\<string> | Promise used to return the application type.| 1004 1005**Example** 1006 1007```ts 1008import featureAbility from '@ohos.ability.featureAbility'; 1009let context = featureAbility.getContext(); 1010context.getAppType().then((data) => { 1011 console.info('getAppType data: ' + JSON.stringify(data)); 1012}); 1013``` 1014 1015## Context.getHapModuleInfo<sup>7+</sup> 1016 1017getHapModuleInfo(callback: AsyncCallback\<HapModuleInfo>): void 1018 1019Obtains the **ModuleInfo** object of the application. This API uses an asynchronous callback to return the result. 1020 1021**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1022 1023**Parameters** 1024 1025| Name | Type | Mandatory | Description | 1026| -------- | ---------------------------------------- | ---- | --------------------------------------- | 1027| callback | AsyncCallback\<[HapModuleInfo](js-apis-bundle-HapModuleInfo.md)> | Yes | Callback used to return the **ModuleInfo** object.| 1028 1029**Example** 1030 1031```ts 1032import featureAbility from '@ohos.ability.featureAbility'; 1033let context = featureAbility.getContext(); 1034context.getHapModuleInfo((err, data) => { 1035 console.info('getHapModuleInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 1036}); 1037``` 1038 1039## Context.getHapModuleInfo<sup>7+</sup> 1040 1041getHapModuleInfo(): Promise\<HapModuleInfo> 1042 1043Obtains the **ModuleInfo** object of the application. This API uses a promise to return the result. 1044 1045**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1046 1047**Return value** 1048 1049| Type | Description | 1050| ---------------------------------------- | ------------------ | 1051| Promise\<[HapModuleInfo](js-apis-bundle-HapModuleInfo.md)> | Promise used to return the **ModuleInfo** object.| 1052 1053**Example** 1054 1055```ts 1056import featureAbility from '@ohos.ability.featureAbility'; 1057let context = featureAbility.getContext(); 1058context.getHapModuleInfo().then((data) => { 1059 console.info('getHapModuleInfo data: ' + JSON.stringify(data)); 1060}); 1061``` 1062 1063## Context.getAppVersionInfo<sup>7+</sup> 1064 1065getAppVersionInfo(callback: AsyncCallback\<AppVersionInfo>): void 1066 1067Obtains the version information of the application. This API uses an asynchronous callback to return the result. 1068 1069**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1070 1071**Parameters** 1072 1073| Name | Type | Mandatory | Description | 1074| -------- | ---------------------------------------- | ---- | ------------------------------ | 1075| callback | AsyncCallback\<[AppVersionInfo](js-apis-inner-app-appVersionInfo.md)> | Yes | Callback used to return the version information.| 1076 1077**Example** 1078 1079```ts 1080import featureAbility from '@ohos.ability.featureAbility'; 1081let context = featureAbility.getContext(); 1082context.getAppVersionInfo((err, data) => { 1083 console.info('getAppVersionInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 1084}); 1085``` 1086 1087## Context.getAppVersionInfo<sup>7+</sup> 1088 1089getAppVersionInfo(): Promise\<AppVersionInfo> 1090 1091Obtains the version information of the application. This API uses a promise to return the result. 1092 1093**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1094 1095**Return value** 1096 1097| Type | Description | 1098| ---------------------------------------- | --------- | 1099| Promise\<[AppVersionInfo](js-apis-inner-app-appVersionInfo.md)> | Promise used to return the version information.| 1100 1101**Example** 1102 1103```ts 1104import featureAbility from '@ohos.ability.featureAbility'; 1105let context = featureAbility.getContext(); 1106context.getAppVersionInfo().then((data) => { 1107 console.info('getAppVersionInfo data: ' + JSON.stringify(data)); 1108}); 1109``` 1110 1111## Context.getAbilityInfo<sup>7+</sup> 1112 1113getAbilityInfo(callback: AsyncCallback\<AbilityInfo>): void 1114 1115Obtains information about this ability. This API uses an asynchronous callback to return the result. 1116 1117**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1118 1119**Parameters** 1120 1121| Name | Type | Mandatory | Description | 1122| -------- | ---------------------------------------- | ---- | --------------------------------------- | 1123| callback | AsyncCallback\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Yes | Callback used to return the ability information.| 1124 1125**Example** 1126 1127```ts 1128import featureAbility from '@ohos.ability.featureAbility'; 1129let context = featureAbility.getContext(); 1130context.getAbilityInfo((err, data) => { 1131 console.info('getAbilityInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 1132}); 1133``` 1134 1135## Context.getAbilityInfo<sup>7+</sup> 1136 1137getAbilityInfo(): Promise\<AbilityInfo> 1138 1139Obtains information about this ability. This API uses a promise to return the result. 1140 1141**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1142 1143**Return value** 1144 1145| Type | Description | 1146| ---------------------------------------- | ------------------ | 1147| Promise\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Promise used to return the ability information.| 1148 1149**Example** 1150 1151```ts 1152import featureAbility from '@ohos.ability.featureAbility'; 1153let context = featureAbility.getContext(); 1154context.getAbilityInfo().then((data) => { 1155 console.info('getAbilityInfo data: ' + JSON.stringify(data)); 1156}); 1157``` 1158 1159## Context.getApplicationContext<sup>7+</sup> 1160 1161getApplicationContext(): Context 1162 1163Obtains the context of the application. 1164 1165**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1166 1167**Return value** 1168 1169| Type | Description | 1170| ------- | ---------- | 1171| Context | Application context.| 1172 1173**Example** 1174 1175```ts 1176import featureAbility from '@ohos.ability.featureAbility'; 1177let context = featureAbility.getContext().getApplicationContext(); 1178``` 1179 1180## Context.isUpdatingConfigurations<sup>7+</sup> 1181 1182isUpdatingConfigurations(callback: AsyncCallback\<boolean>): void; 1183 1184Checks whether the configuration of this ability is being updated. This API uses an asynchronous callback to return the result. 1185 1186**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1187 1188**Parameters** 1189 1190| Name | Type | Mandatory | Description | 1191| -------- | ----------------------- | ---- | ----------------------------- | 1192| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the configuration of the capability is being updated; returns **false** otherwise.| 1193 1194**Example** 1195 1196```ts 1197import featureAbility from '@ohos.ability.featureAbility'; 1198let context = featureAbility.getContext(); 1199context.isUpdatingConfigurations((err, data) => { 1200 console.info('isUpdatingConfigurations err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); 1201}); 1202``` 1203 1204## Context.isUpdatingConfigurations<sup>7+</sup> 1205 1206isUpdatingConfigurations(): Promise\<boolean>; 1207 1208Checks whether the configuration of this ability is being updated. This API uses a promise to return the result. 1209 1210**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1211 1212**Return value** 1213 1214| Type | Description | 1215| ----------------- | ----------------------------- | 1216| Promise\<boolean> | Returns **true** if the configuration of the capability is being updated; returns **false** otherwise.| 1217 1218**Example** 1219 1220```ts 1221import featureAbility from '@ohos.ability.featureAbility'; 1222let context = featureAbility.getContext(); 1223context.isUpdatingConfigurations().then((data) => { 1224 console.info('isUpdatingConfigurations data: ' + JSON.stringify(data)); 1225}); 1226``` 1227 1228## Context.printDrawnCompleted<sup>7+</sup> 1229 1230printDrawnCompleted(callback: AsyncCallback\<void>): void; 1231 1232Notifies the system of the time required to draw this page function. This API uses an asynchronous callback to return the result. 1233 1234**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1235 1236**Parameters** 1237 1238| Name | Type | Mandatory | Description | 1239| -------- | -------------------- | ---- | ----------- | 1240| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 1241 1242**Example** 1243 1244```ts 1245import featureAbility from '@ohos.ability.featureAbility'; 1246let context = featureAbility.getContext(); 1247context.printDrawnCompleted((err) => { 1248 console.error('printDrawnCompleted err: ' + JSON.stringify(err)); 1249}); 1250``` 1251 1252## Context.printDrawnCompleted<sup>7+</sup> 1253 1254printDrawnCompleted(): Promise\<void>; 1255 1256Notifies the system of the time required to draw this page function. This API uses a promise to return the result. 1257 1258**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1259 1260**Return value** 1261 1262| Type | Description | 1263| -------------- | --------------- | 1264| Promise\<void> | Promise used to return the result.| 1265 1266**Example** 1267 1268```ts 1269import featureAbility from '@ohos.ability.featureAbility'; 1270let context = featureAbility.getContext(); 1271context.printDrawnCompleted().then((data) => { 1272 console.info('printDrawnCompleted data: ' + JSON.stringify(data)); 1273}); 1274``` 1275 1276 1277## PermissionOptions<sup>7+</sup> 1278 1279**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1280 1281| Name | Readable/Writable| Type | Mandatory | Description | 1282| ---- | ---- | ------ | ---- | ----- | 1283| pid | Read-only | number | No | Process ID.| 1284| uid | Read-only | number | No | User ID.| 1285 1286## PermissionRequestResult<sup>7+</sup> 1287 1288**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1289 1290| Name | Readable/Writable| Type | Mandatory | Description | 1291| ----------- | ---- | -------------- | ---- | ---------- | 1292| requestCode | Read-only | number | Yes | Request code passed.| 1293| permissions | Read-only | Array\<string> | Yes | Permissions requested. | 1294| authResults | Read-only | Array\<number> | Yes | Permission request result. | 1295