• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Context
2
3## Modules to Import
4
5```js
6import featureAbility from '@ohos.ability.featureAbility'
7import bundle from '@ohos.bundle'
8```
9
10The **Context** object is created in a **featureAbility** and returned through its **getContext()** API. Therefore, you must import the **@ohos.ability.featureAbility** package before using the **Context** module. An example is as follows:
11
12```js
13import featureAbility from '@ohos.ability.featureAbility'
14var context = featureAbility.getContext();
15context.getOrCreateLocalDir()
16```
17
18## Context.getOrCreateLocalDir
19
20getOrCreateLocalDir(callback: AsyncCallback\<string>): void
21
22Obtains the local root directory of the application. This API uses an asynchronous callback to return the result.
23
24If this API is called for the first time, a root directory will be created.
25
26**System capability**: SystemCapability.Ability.AbilityRuntime.Core
27
28**Parameters**
29
30| Name    | Type                  | Mandatory| Description                      |
31| -------- | ---------------------- | ---- | -------------------------- |
32| callback | AsyncCallback\<string> | Yes  | Callback used to return the local root directory.|
33
34**Example**
35
36```js
37import featureAbility from '@ohos.ability.featureAbility'
38var context = featureAbility.getContext();
39context.getOrCreateLocalDir((err, data)=>{
40    console.info("data=" + data);
41})
42```
43
44
45
46## Context.getOrCreateLocalDir
47
48getOrCreateLocalDir(): Promise\<string>
49
50Obtains the local root directory of the application. This API uses a promise to return the result.
51
52If this API is called for the first time, a root directory will be created.
53
54**System capability**: SystemCapability.Ability.AbilityRuntime.Core
55
56**Return value**
57
58| Type            | Description                  |
59| ---------------- | ---------------------- |
60| Promise\<string> | Promise used to return the local root directory.|
61
62**Example**
63
64```js
65import featureAbility from '@ohos.ability.featureAbility'
66var context = featureAbility.getContext();
67context.getOrCreateLocalDir().then((data) => {
68    console.info("data=" + data);
69});
70```
71
72
73
74## Context.verifyPermission
75
76verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\<number>): void
77
78Verifies whether a specific PID and UID have the given permission. This API uses an asynchronous callback to return the result.
79
80**System capability**: SystemCapability.Ability.AbilityRuntime.Core
81
82**Parameters**
83
84| Name      | Type                                   | Mandatory| Description                                 |
85| ---------- | --------------------------------------- | ---- | ------------------------------------- |
86| permission | string                                  | Yes  | Name of the permission to verify.                     |
87| options    | [PermissionOptions](#permissionoptions) | Yes  | Permission options.                           |
88| 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.|
89
90**Example**
91
92```js
93import featureAbility from '@ohos.ability.featureAbility'
94import bundle from '@ohos.bundle'
95var context = featureAbility.getContext();
96bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{
97	context.verifyPermission("com.example.permission", datainfo.uid);
98});
99```
100
101
102
103## Context.verifyPermission
104
105verifyPermission(permission: string, callback: AsyncCallback\<number>): void
106
107Verifies whether the current PID and UID have the given permission. This API uses an asynchronous callback to return the result.
108
109**System capability**: SystemCapability.Ability.AbilityRuntime.Core
110
111**Parameters**
112
113| Name      | Type                  | Mandatory| Description                                 |
114| ---------- | ---------------------- | ---- | ------------------------------------- |
115| permission | string                 | Yes  | Name of the permission to verify.                     |
116| 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.|
117
118**Example**
119
120```js
121import featureAbility from '@ohos.ability.featureAbility'
122var context = featureAbility.getContext();
123context.verifyPermission("com.example.permission")
124```
125
126## Context.verifyPermission
127
128verifyPermission(permission: string, options?: PermissionOptions): Promise\<number>
129
130Verifies whether a specific PID and UID have the given permission. This API uses a promise to return the result.
131
132**System capability**: SystemCapability.Ability.AbilityRuntime.Core
133
134**Parameters**
135
136| Name      | Type                                   | Mandatory| Description            |
137| ---------- | --------------------------------------- | ---- | ---------------- |
138| permission | string                                  | Yes  | Name of the permission to verify.|
139| options    | [PermissionOptions](#permissionoptions) | No  | Permission options.      |
140
141**Return value**
142
143| Type            | Description                                                       |
144| ---------------- | ----------------------------------------------------------- |
145| 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.|
146
147**Example**
148
149```js
150import featureAbility from '@ohos.ability.featureAbility'
151var context = featureAbility.getContext();
152var Permission = context.PermissionOptions(1,1);
153context.verifyPermission('com.context.permission',Permission).then((data) => {
154    console.info("======================>verifyPermissionCallback====================>");
155    console.info("====>data====>" + JSON.stringify(data));
156});
157```
158
159
160
161## Context.requestPermissionsFromUser
162
163requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#permissionrequestresult)>): void
164
165Requests certain permissions from the system. This API uses an asynchronous callback to return the result.
166
167**System capability**: SystemCapability.Ability.AbilityRuntime.Core
168
169**Parameters**
170
171| Name          | Type                                                        | Mandatory| Description                                           |
172| -------------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- |
173| permissions    | Array\<string>                                               | Yes  | Permissions to request. This parameter cannot be **null**.       |
174| requestCode    | number                                                       | Yes  | Request code to be passed to **PermissionRequestResult**.|
175| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes  | Callback used to return the permission request result.                             |
176
177**Example**
178
179```js
180import featureAbility from '@ohos.ability.featureAbility'
181var context = featureAbility.getContext();
182context.requestPermissionsFromUser(
183    ["com.example.permission1",
184     "com.example.permission2",
185     "com.example.permission3",
186     "com.example.permission4",
187     "com.example.permission5"],
188    1,(err, data)=>{
189        console.info("====>requestdata====>" + JSON.stringify(data));
190        console.info("====>requesterrcode====>" + JSON.stringify(err.code));
191    }
192)
193```
194
195
196## Context.requestPermissionsFromUser<sup>7+</sup>
197
198requestPermissionsFromUser(permissions: Array\<string>, requestCode: number): Promise\<[PermissionRequestResult](#permissionrequestresult7)>
199
200Requests certain permissions from the system. This API uses a promise to return the result.
201
202**System capability**: SystemCapability.Ability.AbilityRuntime.Core
203
204**Parameters**
205
206| Name          | Type                | Mandatory | Description                                         |
207| -------------- | ------------------- | ----- | -------------------------------------------- |
208| permissions    | Array\<string>      | Yes   | Permissions to request. This parameter cannot be **null**.        |
209| requestCode    | number              | Yes   | Request code to be passed to **PermissionRequestResult**.|
210
211**Return value**
212
213| Type                                                          | Description            |
214| ------------------------------------------------------------- | ---------------- |
215| Promise\<[PermissionRequestResult](#permissionrequestresult7)> | Promise used to return the permission request result.|
216
217**Example**
218
219```js
220import featureAbility from '@ohos.ability.featureAbility'
221var context = featureAbility.getContext();
222context.requestPermissionsFromUser(
223    ["com.example.permission1",
224     "com.example.permission2",
225     "com.example.permission3",
226     "com.example.permission4",
227     "com.example.permission5"],
228    1).then((data)=>{
229        console.info("====>requestdata====>" + JSON.stringify(data));
230    });
231```
232
233
234
235## Context.getApplicationInfo
236
237getApplicationInfo(callback: AsyncCallback\<ApplicationInfo>): void
238
239Obtains information about the current application. This API uses an asynchronous callback to return the result.
240
241**System capability**: SystemCapability.Ability.AbilityRuntime.Core
242
243**Parameters**
244
245| Name    | Type                           | Mandatory| Description                    |
246| -------- | ------------------------------- | ---- | ------------------------ |
247| callback | AsyncCallback\<ApplicationInfo> | Yes  | Callback used to return the application information.|
248
249**Example**
250
251```js
252import featureAbility from '@ohos.ability.featureAbility'
253var context = featureAbility.getContext();
254context.getApplicationInfo()
255```
256
257
258
259## Context.getApplicationInfo
260
261getApplicationInfo(): Promise\<ApplicationInfo>
262
263Obtains information about the current application. This API uses a promise to return the result.
264
265**System capability**: SystemCapability.Ability.AbilityRuntime.Core
266
267**Return value**
268
269| Type                     | Description              |
270| ------------------------- | ------------------ |
271| Promise\<ApplicationInfo> | Promise used to return the application information.|
272
273**Example**
274
275```js
276import featureAbility from '@ohos.ability.featureAbility'
277var context = featureAbility.getContext();
278context.getApplicationInfo().then((data) => {
279    console.info("=====================>getApplicationInfoCallback===================>");
280    console.info("====>data====>" + JSON.stringify(data));
281});
282```
283
284
285
286## Context.getBundleName
287
288getBundleName(callback: AsyncCallback\<string>): void
289
290Obtains the bundle name of this ability. This API uses an asynchronous callback to return the result.
291
292**System capability**: SystemCapability.Ability.AbilityRuntime.Core
293
294**Parameters**
295
296| Name    | Type                  | Mandatory| Description                         |
297| -------- | ---------------------- | ---- | ----------------------------- |
298| callback | AsyncCallback\<string> | Yes  | Callback used to return the bundle name.|
299
300**Example**
301
302```js
303import featureAbility from '@ohos.ability.featureAbility'
304var context = featureAbility.getContext();
305context.getBundleName()
306```
307
308
309
310## Context.getBundleName
311
312getBundleName(): Promise\<string>
313
314Obtains the bundle name of this ability. This API uses a promise to return the result.
315
316**System capability**: SystemCapability.Ability.AbilityRuntime.Core
317
318**Return value**
319
320| Type            | Description                     |
321| ---------------- | ------------------------- |
322| Promise\<string> | Promise used to return the bundle name.|
323
324**Example**
325
326```js
327import featureAbility from '@ohos.ability.featureAbility'
328var context = featureAbility.getContext();
329context.getBundleName().then((data) => {
330    console.info("=======================>getBundleNameCallback====================>");
331    console.info("====>data====>" + JSON.stringify(data));
332});
333```
334
335
336
337## Context.getProcessInfo
338
339getProcessInfo(callback: AsyncCallback\<ProcessInfo>): void
340
341Obtains information about the current process, including the PID and process name. This API uses an asynchronous callback to return the result.
342
343**System capability**: SystemCapability.Ability.AbilityRuntime.Core
344
345**Parameters**
346
347| Name    | Type                       | Mandatory| Description                |
348| -------- | --------------------------- | ---- | -------------------- |
349| callback | AsyncCallback\<ProcessInfo> | Yes  | Callback used to return the process information.|
350
351**Example**
352
353```js
354import featureAbility from '@ohos.ability.featureAbility'
355var context = featureAbility.getContext();
356context.getProcessInfo()
357```
358
359
360
361## Context.getProcessInfo
362
363getProcessInfo(): Promise\<ProcessInfo>
364
365Obtains information about the current process, including the PID and process name. This API uses a promise to return the result.
366
367**System capability**: SystemCapability.Ability.AbilityRuntime.Core
368
369**Return value**
370
371| Type                 | Description          |
372| --------------------- | -------------- |
373| Promise\<ProcessInfo> | Promise used to return the process information.|
374
375**Example**
376
377```js
378import featureAbility from '@ohos.ability.featureAbility'
379var context = featureAbility.getContext();
380context.getProcessInfo().then((data) => {
381    console.info("=======================>getProcessInfoCallback====================>");
382    console.info("====>data====>" + JSON.stringify(data));
383});
384```
385
386
387
388## Context.getElementName
389
390getElementName(callback: AsyncCallback\<ElementName>): void
391
392Obtains the **ohos.bundle.ElementName** object of this ability. This API uses an asynchronous callback to return the result.
393
394This API is available only to Page abilities.
395
396**System capability**: SystemCapability.Ability.AbilityRuntime.Core
397
398**Parameters**
399
400| Name    | Type                       | Mandatory| Description                                          |
401| -------- | --------------------------- | ---- | ---------------------------------------------- |
402| callback | AsyncCallback\<ElementName> | Yes  | Callback used to return the **ohos.bundle.ElementName** object.|
403
404**Example**
405
406```js
407import featureAbility from '@ohos.ability.featureAbility'
408var context = featureAbility.getContext();
409context.getElementName()
410```
411
412
413
414## Context.getElementName
415
416getElementName(): Promise\<ElementName>
417
418Obtains the **ohos.bundle.ElementName** object of this ability. This API uses a promise to return the result.
419
420This API is available only to Page abilities.
421
422**System capability**: SystemCapability.Ability.AbilityRuntime.Core
423
424**Return value**
425
426| Type                 | Description                                      |
427| --------------------- | ------------------------------------------ |
428| Promise\<ElementName> | Promise used to return the **ohos.bundle.ElementName** object.|
429
430**Example**
431
432```js
433import featureAbility from '@ohos.ability.featureAbility'
434var context = featureAbility.getContext();
435context.getElementName().then((data) => {
436    console.info("=======================>getElementNameCallback====================>");
437    console.info("====>data====>" + JSON.stringify(data));
438});
439```
440
441## Context.getProcessName
442
443getProcessName(callback: AsyncCallback\<string>): void
444
445Obtains the name of the current process. This API uses an asynchronous callback to return the result.
446
447**System capability**: SystemCapability.Ability.AbilityRuntime.Core
448
449**Parameters**
450
451| Name    | Type                  | Mandatory| Description                |
452| -------- | ---------------------- | ---- | -------------------- |
453| callback | AsyncCallback\<string> | Yes  | Callback used to return the process name.|
454
455**Example**
456
457```js
458import featureAbility from '@ohos.ability.featureAbility'
459var context = featureAbility.getContext();
460context.getProcessName()
461```
462
463
464
465## Context.getProcessName
466
467getProcessName(): Promise\<string>
468
469Obtains the name of the current process. This API uses a promise to return the result.
470
471**System capability**: SystemCapability.Ability.AbilityRuntime.Core
472
473**Return value**
474
475| Type            | Description                |
476| ---------------- | -------------------- |
477| Promise\<string> | Promise used to return the process name.|
478
479**Example**
480
481```js
482import featureAbility from '@ohos.ability.featureAbility'
483var context = featureAbility.getContext();
484context.getProcessName().then((data) => {
485    console.info("=======================>getProcessNameCallback====================>");
486    console.info("====>data====>" + JSON.stringify(data));
487});
488```
489
490
491
492## Context.getCallingBundle
493
494getCallingBundle(callback: AsyncCallback\<string>): void
495
496Obtains the bundle name of the calling ability. This API uses an asynchronous callback to return the result.
497
498**System capability**: SystemCapability.Ability.AbilityRuntime.Core
499
500**Parameters**
501
502| Name    | Type                  | Mandatory| Description                     |
503| -------- | ---------------------- | ---- | ------------------------- |
504| callback | AsyncCallback\<string> | Yes  | Callback used to return the bundle name.|
505
506**Example**
507
508```js
509import featureAbility from '@ohos.ability.featureAbility'
510var context = featureAbility.getContext();
511context.getCallingBundle()
512```
513
514
515
516## Context.getCallingBundle
517
518getCallingBundle(): Promise\<string>
519
520Obtains the bundle name of the calling ability. This API uses a promise to return the result.
521
522**System capability**: SystemCapability.Ability.AbilityRuntime.Core
523
524**Return value**
525
526| Type           | Description                     |
527| --------------- | ------------------------- |
528| Promise\<string> | Promise used to return the bundle name.|
529
530**Example**
531
532```js
533import featureAbility from '@ohos.ability.featureAbility'
534var context = featureAbility.getContext();
535context.getCallingBundle().then((data) => {
536    console.info("======================>getCallingBundleCallback====================>");
537    console.info("====>data====>" + JSON.stringify(data));
538});
539```
540
541## Context.getCacheDir
542
543getCacheDir(callback: AsyncCallback\<string>): void
544
545Obtains the cache directory of the application in the internal storage. This API uses an asynchronous callback to return the result.
546
547**System capability**: SystemCapability.Ability.AbilityRuntime.Core
548
549**Parameters**
550
551| Name    | Type                  | Mandatory| Description                     |
552| -------- | ---------------------- | ---- | ------------------------- |
553| callback | AsyncCallback\<string> | Yes  | Callback used to return the cache directory.|
554
555**Example**
556
557```js
558import featureAbility from '@ohos.ability.featureAbility'
559var context = featureAbility.getCacheDir();
560context.getCacheDir((err, data) => {
561    if (err) {
562        console.error('Operation failed. Cause: ' + JSON.stringify(err));
563        return;
564    }
565    console.info('Operation successful. Data:' + JSON.stringify(data));
566});
567```
568
569## Context.getCacheDir
570
571getCacheDir(): Promise\<string>
572
573Obtains the cache directory of the application in the internal storage. This API uses a promise to return the result.
574
575**System capability**: SystemCapability.Ability.AbilityRuntime.Core
576
577**Return value**
578
579| Type           | Description                     |
580| --------------- | ------------------------- |
581| Promise\<string> | Promise used to return the cache directory.|
582
583**Example**
584
585```js
586import featureAbility from '@ohos.ability.featureAbility'
587var context = featureAbility.getContext();
588context.getCacheDir().then((data) => {
589    console.info("======================>getCacheDirPromsie====================>");
590    console.info("====>data====>" + JSON.stringify(data));
591});
592```
593
594## Context.getFilesDir
595
596getFilesDir(callback: AsyncCallback\<string>): void
597
598Obtains the file directory of the application in the internal storage. This API uses an asynchronous callback to return the result.
599
600**System capability**: SystemCapability.Ability.AbilityRuntime.Core
601
602**Parameters**
603
604| Name    | Type                  | Mandatory| Description                     |
605| -------- | ---------------------- | ---- | ------------------------- |
606| callback | AsyncCallback\<string> | Yes  | Callback used to return the file directory.|
607
608**Example**
609
610```js
611import featureAbility from '@ohos.ability.featureAbility'
612var context = featureAbility.getFilesDir();
613context.getFilesDir((err, data) => {
614    if (err) {
615        console.error('Operation failed. Cause: ' + JSON.stringify(err));
616        return;
617    }
618    console.info('Operation successful. Data:' + JSON.stringify(data));
619});
620```
621
622## Context.getFilesDir
623
624getFilesDir(): Promise\<string>
625
626Obtains the file directory of the application in the internal storage. This API uses a promise to return the result.
627
628**System capability**: SystemCapability.Ability.AbilityRuntime.Core
629
630**Return value**
631
632| Type           | Description                     |
633| --------------- | ------------------------- |
634| Promise\<string> | Promise used to return the file directory.|
635
636**Example**
637
638```js
639import featureAbility from '@ohos.ability.featureAbility'
640var context = featureAbility.getContext();
641context.getFilesDir().then((data) => {
642    console.info("======================>getFilesDirPromsie====================>");
643    console.info("====>data====>" + JSON.stringify(data));
644});
645```
646
647## Context.getOrCreateDistributedDir
648
649getOrCreateDistributedDir(callback: AsyncCallback\<string>): void
650
651Obtains the distributed file path for storing ability or application data files. This API uses an asynchronous callback to return the result.
652
653If the distributed file path does not exist, the system will create one and return the created path.
654
655**System capability**: SystemCapability.Ability.AbilityRuntime.Core
656
657**Parameters**
658
659| Name    | Type                  | Mandatory| Description                     |
660| -------- | ---------------------- | ---- | ------------------------- |
661| callback | AsyncCallback\<string> | Yes  | Callback used to return the distributed file path. If the distributed file path does not exist, the system will create one and return the created path.|
662
663**Example**
664
665```js
666import featureAbility from '@ohos.ability.featureAbility'
667var context = featureAbility.getContext();
668context.getOrCreateDistributedDir((err, data) => {
669    if (err) {
670        console.error('Operation failed. Cause: ' + JSON.stringify(err));
671        return;
672    }
673    console.info('Operation successful. Data:' + JSON.stringify(data));
674});
675```
676
677## Context.getOrCreateDistributedDir
678
679getOrCreateDistributedDir(): Promise\<string>
680
681Obtains the distributed file path for storing ability or application data files. This API uses a promise to return the result.
682
683If the distributed file path does not exist, the system will create one and return the created path.
684
685**System capability**: SystemCapability.Ability.AbilityRuntime.Core
686
687**Return value**
688
689| Type           | Description                     |
690| --------------- | ------------------------- |
691| Promise\<string> | Promise used to return the distributed file path. If this API is called for the first time, a new path will be created.|
692
693**Example**
694
695```js
696import featureAbility from '@ohos.ability.featureAbility'
697var context = featureAbility.getContext();
698context.getOrCreateDistributedDir().then((data) => {
699    console.info("====>data====>" + JSON.stringify(data));
700});
701```
702
703## Context.getAppType
704
705getAppType(callback: AsyncCallback\<string>): void
706
707Obtains the application type. This API uses an asynchronous callback to return the result.
708
709**System capability**: SystemCapability.Ability.AbilityRuntime.Core
710
711**Parameters**
712
713| Name    | Type                  | Mandatory| Description                     |
714| -------- | ---------------------- | ---- | ------------------------- |
715| callback | AsyncCallback\<string> | Yes  | Callback used to return the application type.|
716
717**Example**
718
719```js
720import featureAbility from '@ohos.ability.featureAbility'
721var context = featureAbility.getContext();
722context.getAppType((err, data) => {
723    if (err) {
724        console.error('Operation failed. Cause: ' + JSON.stringify(err));
725        return;
726    }
727    console.info('Operation successful. Data:' + JSON.stringify(data));
728});
729```
730
731## Context.getAppType
732
733getAppType(): Promise\<string>
734
735Obtains the application type. This API uses a promise to return the result.
736
737**System capability**: SystemCapability.Ability.AbilityRuntime.Core
738
739**Return value**
740
741| Type           | Description                     |
742| --------------- | ------------------------- |
743| Promise\<string> | Promise used to return the application type.|
744
745**Example**
746
747```js
748import featureAbility from '@ohos.ability.featureAbility'
749var context = featureAbility.getContext();
750context.getAppType().then((data) => {
751    console.info("====>data====>" + JSON.stringify(data));
752});
753```
754
755## Context.getHapModuleInfo
756
757getHapModuleInfo(callback: AsyncCallback\<HapModuleInfo>): void
758
759Obtains the **ModuleInfo** object of the application. This API uses an asynchronous callback to return the result.
760
761**System capability**: SystemCapability.Ability.AbilityRuntime.Core
762
763**Parameters**
764
765| Name    | Type                  | Mandatory| Description                     |
766| -------- | ---------------------- | ---- | ------------------------- |
767| callback | AsyncCallback\<[HapModuleInfo](#hapmoduleinfo)> | Yes  | Callback used to return the **ModuleInfo** object.|
768
769**Example**
770
771```js
772import featureAbility from '@ohos.ability.featureAbility'
773var context = featureAbility.getContext();
774context.getHapModuleInfo((err, data) => {
775    if (err) {
776        console.error('Operation failed. Cause: ' + JSON.stringify(err));
777        return;
778    }
779    console.info('Operation successful. Data:' + JSON.stringify(data));
780});
781```
782
783## Context.getHapModuleInfo
784
785getHapModuleInfo(): Promise\<HapModuleInfo>
786
787Obtains the **ModuleInfo** object of the application. This API uses a promise to return the result.
788
789**System capability**: SystemCapability.Ability.AbilityRuntime.Core
790
791**Return value**
792
793| Type           | Description                     |
794| --------------- | ------------------------- |
795| Promise\<[HapModuleInfo](#hapmoduleinfo)> | Promise used to return the **ModuleInfo** object.|
796
797**Example**
798
799```js
800import featureAbility from '@ohos.ability.featureAbility'
801var context = featureAbility.getContext();
802context.getHapModuleInfo().then((data) => {
803    console.info("====>data====>" + JSON.stringify(data));
804});
805```
806
807## Context.getAppVersionInfo
808
809getAppVersionInfo(callback: AsyncCallback\<HapModuleInfo>): void
810
811Obtains the version information of the application. This API uses an asynchronous callback to return the result.
812
813**System capability**: SystemCapability.Ability.AbilityRuntime.Core
814
815**Parameters**
816
817| Name    | Type                  | Mandatory| Description                     |
818| -------- | ---------------------- | ---- | ------------------------- |
819| callback | AsyncCallback\<[AppVersionInfo](#appversioninfo)> | Yes  | Callback used to return the version information.|
820
821**Example**
822
823```js
824import featureAbility from '@ohos.ability.featureAbility'
825var context = featureAbility.getContext();
826context.getAppVersionInfo((err, data) => {
827    if (err) {
828        console.error('Operation failed. Cause: ' + JSON.stringify(err));
829        return;
830    }
831    console.info('Operation successful. Data:' + JSON.stringify(data));
832});
833```
834
835## Context.getAppVersionInfo
836
837getAppVersionInfo(): Promise\<AppVersionInfo>
838
839Obtains the version information of the application. This API uses a promise to return the result.
840
841**System capability**: SystemCapability.Ability.AbilityRuntime.Core
842
843**Return value**
844
845| Type           | Description                     |
846| --------------- | ------------------------- |
847| Promise\<[AppVersionInfo](#appversioninfo)> | Promise used to return the version information.|
848
849**Example**
850
851```js
852import featureAbility from '@ohos.ability.featureAbility'
853var context = featureAbility.getContext();
854context.getAppVersionInfo().then((data) => {
855    console.info("====>data====>" + JSON.stringify(data));
856});
857```
858
859## Context.getAbilityInfo
860
861getAbilityInfo(callback: AsyncCallback\<AbilityInfo>): void
862
863Obtains information about this ability. This API uses an asynchronous callback to return the result.
864
865**System capability**: SystemCapability.Ability.AbilityRuntime.Core
866
867**Parameters**
868
869| Name    | Type                  | Mandatory| Description                     |
870| -------- | ---------------------- | ---- | ------------------------- |
871| callback | AsyncCallback\<[AbilityInfo](#abilityInfo)> | Yes  |Callback used to return the ability information.|
872
873**Example**
874
875```js
876import featureAbility from '@ohos.ability.featureAbility'
877var context = featureAbility.getContext();
878context.getAbilityInfo((err, data) => {
879    if (err) {
880        console.error('Operation failed. Cause: ' + JSON.stringify(err));
881        return;
882    }
883    console.info('Operation successful. Data:' + JSON.stringify(data));
884});
885```
886
887## Context.getAbilityInfo
888
889getAbilityInfo(): Promise\<AbilityInfo>
890
891Obtains information about this ability. This API uses a promise to return the result.
892
893**System capability**: SystemCapability.Ability.AbilityRuntime.Core
894
895**Return value**
896
897| Type           | Description                     |
898| --------------- | ------------------------- |
899| Promise\<[AbilityInfo](#abilityInfo)> | Promise used to return the ability information.|
900
901**Example**
902
903```js
904import featureAbility from '@ohos.ability.featureAbility'
905var context = featureAbility.getContext();
906context.getAbilityInfo().then((data) => {
907    console.info("====>data====>" + JSON.stringify(data));
908});
909```
910
911## Context.getApplicationContext
912
913getApplicationContext(): Context
914
915Obtains the context of the application.
916
917**System capability**: SystemCapability.Ability.AbilityRuntime.Core
918
919**Return value**
920
921| Type     | Description  |
922| --------- |------ |
923|  Context |Application context.|
924
925**Example**
926
927```js
928import featureAbility from '@ohos.ability.featureAbility'
929var context = featureAbility.getContext().getApplicationContext();
930```
931
932## Context.getExternalCacheDir
933
934getExternalCacheDir(callback: AsyncCallback\<string>): void
935
936Obtains the external cache directory of the application. This API uses an asynchronous callback to return the result.
937
938**System capability**: SystemCapability.Ability.AbilityRuntime.Core
939
940**Parameters**
941
942| Name      | Type                    | Mandatory  | Description                |
943| -------- | ---------------------- | ---- | ------------------ |
944| callback | AsyncCallback\<string> | Yes   | Callback used to return the absolute path of the cache directory.|
945
946**Example**
947
948```js
949import featureAbility from '@ohos.ability.featureAbility'
950var context = featureAbility.getContext();
951context.getExternalCacheDir()
952```
953
954## Context.getExternalCacheDir
955
956getExternalCacheDir(): Promise\<string>;
957
958Obtains the external cache directory of the application. This API uses a promise to return the result.
959
960**System capability**: SystemCapability.Ability.AbilityRuntime.Core
961
962**Return value**
963
964| Type              | Description              |
965| ---------------- | ---------------- |
966| Promise\<string> | Promise used to return the absolute path of the cache directory.|
967
968**Example**
969
970```js
971import featureAbility from '@ohos.ability.featureAbility'
972var context = featureAbility.getContext();
973context.getExternalCacheDir().then((data) => {
974    console.info("=======================>getExternalCacheDirCallback====================>");
975    console.info("====>data====>" + JSON.stringify(data));
976});
977```
978
979## PermissionOptions
980
981**System capability**: SystemCapability.Ability.AbilityRuntime.Core
982
983| Name| Readable/Writable| Type  | Mandatory| Description  |
984| ---- | -------- | ------ | ---- | ------ |
985| pid  | Read-only    | number | No  | Process ID.|
986| uid  | Read-only    | number | No  | User ID.|
987
988## PermissionRequestResult
989
990**System capability**: SystemCapability.Ability.AbilityRuntime.Core
991
992| Name       | Readable/Writable| Type          | Mandatory| Description              |
993| ----------- | -------- | -------------- | ---- | ------------------ |
994| requestCode | Read-only    | number         | Yes  | Request code passed.|
995| permissions | Read-only    | Array\<string> | Yes  | Permissions requested.    |
996| authResults | Read-only    | Array\<number> | Yes  | Permission request result.   |
997
998## HapModuleInfo
999
1000Describes the HAP module information.
1001
1002| Name              | Type| Readable| Writable| Description|
1003| ------ | ------ | ------ | ------ | ------ |
1004| name             | string        | Yes  | No  | Module name.          |
1005| description      | string        | Yes  | No  | Module description.      |
1006| descriptionId    | number        | Yes  | No  | Module description ID.        |
1007| icon             | string        | Yes  | No  | Module icon.          |
1008| label            | string        | Yes  | No  | Module label.          |
1009| labelId          | number        | Yes  | No  | Module label ID.        |
1010| iconId           | number        | Yes  | No  | Module icon ID.        |
1011| backgroundImg    | string        | Yes  | No  | Module background image.      |
1012| supportedModes   | number        | Yes  | No  | Running modes supported by the module.    |
1013| reqCapabilities  | Array\<string> | Yes  | No  | Capabilities required for module running.|
1014| deviceTypes      | Array\<string> | Yes  | No  | Device types supported by the module.|
1015| abilityInfo      | Array\<AbilityInfo> | Yes  | No  | Ability information.       |
1016| moduleName       | string        | Yes  | No  | Module name.            |
1017| mainAbilityName  | string        | Yes  | No  | Name of the main ability.   |
1018| installationFree | boolean       | Yes  | No  | Whether installation-free is supported.    |
1019| mainElementName | string | Yes| No| Information about the main ability.|
1020
1021## AppVersionInfo
1022
1023| Name            | Type| Readable   | Writable  | Description|
1024| ------          | ------ | ------| ------ | ------    |
1025| appName         | string | Yes   | No    | Module name.     |
1026| versionCode     | number | Yes   | No    | Module description.  |
1027| versionName     | string | Yes   | No    | Module description ID.    |
1028