# @ohos.app.ability.application (Application)
开发者可以通过该模块创建[Context](../../application-models/application-context-stage.md)。
> **说明:**
>
> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
## 导入模块
```ts
import { application } from '@kit.AbilityKit';
```
## application.createModuleContext12+
createModuleContext(context: Context, moduleName: string): Promise\
根据入参Context创建相应模块的Context。
**原子化服务API**:从API version 12开始,该接口支持在元服务中使用。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数**:
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| context | [Context](js-apis-inner-application-context.md) | 是 | 表示应用上下文。 |
| moduleName | string | 是 | 表示应用模块名。 |
**返回值:**
| 类型 | 说明 |
| ------------------ | ------------------- |
| Promise\<[Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md)> | Promise对象。返回创建的Context。 |
**错误码:**
以下错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
| 错误码ID | 错误信息 |
| -------- | --------------- |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
**示例:**
```ts
import { UIAbility, application, common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
export default class EntryAbility extends UIAbility {
onCreate() {
let moduleContext: common.Context;
try {
application.createModuleContext(this.context, 'entry').then((data: Context) => {
moduleContext = data;
console.info('createBundleContext success!');
}).catch((error: BusinessError) => {
let code: number = (error as BusinessError).code;
let message: string = (error as BusinessError).message;
console.error(`createModuleContext failed, error.code: ${code}, error.message: ${message}`);
})
} catch (error) {
let code: number = (error as BusinessError).code;
let message: string = (error as BusinessError).message;
console.error(`createModuleContext failed, error.code: ${code}, error.message: ${message}`);
}
}
}
```
## application.getApplicationContext14+
getApplicationContext(): ApplicationContext
获取应用程序上下文。
> **说明:**
>
>通过该接口取得的ApplicationContext,只支持获取对应的[应用信息](js-apis-bundleManager-applicationInfo.md)和全部的[沙箱路径](js-apis-inner-application-context.md#属性)。
**原子化服务API**:从API version 14开始,该接口支持在元服务中使用。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------------ | ------------------- |
| [ApplicationContext](js-apis-inner-application-applicationContext.md) | 应用上下文Context。 |
**错误码:**
以下错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
| 错误码ID | 错误信息 |
| -------- | --------------- |
| 16000050 | Internal error. |
**示例:**
```ts
import { UIAbility, application } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
export default class EntryAbility extends UIAbility {
onCreate(): void {
try {
let applicationContext = application.getApplicationContext();
} catch (error) {
let code: number = (error as BusinessError).code;
let message: string = (error as BusinessError).message;
console.error(`getApplicationContext failed, error.code: ${code}, error.message: ${message}`);
}
}
}
```