1# @ohos.app.ability.application (Application) (System API) 2 3You can use this module to create a [Context](../../application-models/application-context-stage.md). 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> The APIs of this module can be used only in the stage model. 9 10## Modules to Import 11 12```ts 13import { application } from '@kit.AbilityKit'; 14``` 15## application.createModuleContext<sup>12+</sup> 16 17createModuleContext(context: Context, bundleName: string, moduleName: string): Promise\<Context> 18 19Creates the context for a module. 20 21**Atomic service API**: This API can be used in atomic services since API version 12. 22 23**System capability**: SystemCapability.Ability.AbilityRuntime.Core 24 25**System API**: This is a system API. 26 27**Parameters** 28 29| Name | Type | Mandatory | Description | 30| --------- | ---------------------------------------- | ---- | -------------- | 31| context | [Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md) | Yes| Application context.| 32| bundleName | string | Yes | Bundle name of the application. If an empty string is passed in, the current application is used by default.| 33| moduleName | string | Yes| Module name.| 34 35**Return value** 36 37| Type | Description | 38| ------------------ | ------------------- | 39| Promise\<[Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md)> | Promise used to return the context created.| 40 41**Error codes** 42 43For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 44 45| ID| Error Message | 46| -------- | --------------- | 47| 201 | Permission denied. | 48| 202 | Permission denied, non-system app called system api.| 49| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 50 51**Example** 52 53```ts 54import { UIAbility, application} from '@kit.AbilityKit'; 55import { BusinessError } from '@kit.BasicServicesKit'; 56 57export default class EntryAbility extends UIAbility { 58 onCreate() { 59 let moduleContext: common.Context; 60 try { 61 application.createModuleContext(this.context, 'bundlename', 'entry').then((data: Context)=>{ 62 moduleContext = data; 63 console.info('createModuleContext success!'); 64 }).catch((error : BusinessError)=>{ 65 console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 66 }) 67 } catch (error) { 68 console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 69 } 70 } 71} 72``` 73 74## application.createBundleContext<sup>12+</sup> 75 76createBundleContext(context: Context, bundleName: string): Promise\<Context> 77 78Creates the context for an application. 79 80**Atomic service API**: This API can be used in atomic services since API version 12. 81 82**System capability**: SystemCapability.Ability.AbilityRuntime.Core 83 84**System API**: This is a system API. 85 86**Parameters** 87 88| Name | Type | Mandatory | Description | 89| --------- | ---------------------------------------- | ---- | -------------- | 90| context | [Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md) | Yes| Application context.| 91| bundleName | string | Yes | Bundle name of the application.| 92 93**Return value** 94 95| Type | Description | 96| ------------------ | ------------------- | 97| Promise\<[Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md)> | Promise used to return the context created.| 98 99**Error codes** 100 101For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 102 103| ID| Error Message | 104| -------- | --------------- | 105| 201 | Permission denied. | 106| 202 | Permission denied, non-system app called system api.| 107| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 108 109 110**Example** 111 112```ts 113import { UIAbility, application} from '@kit.AbilityKit'; 114import { BusinessError } from '@kit.BasicServicesKit'; 115 116export default class EntryAbility extends UIAbility { 117 onCreate() { 118 let moduleContext: common.Context; 119 try { 120 application.createBundleContext(this.context, 'bundlename').then((data: Context)=>{ 121 moduleContext = data; 122 console.info('createBundleContext success!'); 123 }).catch((error : BusinessError)=>{ 124 console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 125 }) 126 } catch (error) { 127 console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 128 } 129 } 130} 131``` 132