1e41f4b71Sopenharmony_ci#  @ohos.app.ability.application (Application)(系统接口)
2e41f4b71Sopenharmony_ci开发者可以通过该模块创建[Context](../../application-models/application-context-stage.md)。
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci> **说明:**
5e41f4b71Sopenharmony_ci>
6e41f4b71Sopenharmony_ci> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
7e41f4b71Sopenharmony_ci> 本模块接口仅可在Stage模型下使用。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## 导入模块
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport { application } from '@kit.AbilityKit';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci## application.createModuleContext<sup>12+</sup>
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_cicreateModuleContext(context: Context, bundleName: string, moduleName: string): Promise\<Context>
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci根据入参Context创建相应模块的Context。
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**元服务API:** 从API version 12开始,该接口支持在元服务中使用。
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**参数**:
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci| 参数名        | 类型                                       | 必填   | 说明             |
29e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- |
30e41f4b71Sopenharmony_ci| context | [Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md) | 是 | 表示应用上下文。 | 
31e41f4b71Sopenharmony_ci| bundleName | string   | 是    | 表示应用包名。取值为空字符串时,默认为当前应用。|
32e41f4b71Sopenharmony_ci| moduleName | string | 是 | 表示应用模块名。 |
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**返回值:**
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci| 类型               | 说明                |
37e41f4b71Sopenharmony_ci| ------------------ | ------------------- |
38e41f4b71Sopenharmony_ci| Promise\<[Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md)> | Promise对象。返回创建的Context。 |
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**错误码:**
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci| 错误码ID | 错误信息        |
45e41f4b71Sopenharmony_ci| -------- | --------------- |
46e41f4b71Sopenharmony_ci| 201 | Permission denied. |
47e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api.|
48e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**示例:**
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci```ts
53e41f4b71Sopenharmony_ciimport { UIAbility, application} from '@kit.AbilityKit';
54e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility {
57e41f4b71Sopenharmony_ci  onCreate() {
58e41f4b71Sopenharmony_ci    let moduleContext: common.Context;
59e41f4b71Sopenharmony_ci    try {
60e41f4b71Sopenharmony_ci      application.createModuleContext(this.context, 'bundlename', 'entry').then((data: Context)=>{
61e41f4b71Sopenharmony_ci        moduleContext = data;
62e41f4b71Sopenharmony_ci        console.info('createModuleContext success!');
63e41f4b71Sopenharmony_ci      }).catch((error : BusinessError)=>{
64e41f4b71Sopenharmony_ci        console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
65e41f4b71Sopenharmony_ci      })
66e41f4b71Sopenharmony_ci    } catch (error) {
67e41f4b71Sopenharmony_ci      console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
68e41f4b71Sopenharmony_ci    }
69e41f4b71Sopenharmony_ci  }
70e41f4b71Sopenharmony_ci}
71e41f4b71Sopenharmony_ci```
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci## application.createBundleContext<sup>12+</sup>
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_cicreateBundleContext(context: Context, bundleName: string): Promise\<Context>
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci根据入参Context创建相应应用的Context。
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**元服务API:** 从API version 12开始,该接口支持在元服务中使用。
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci**参数**:
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci| 参数名        | 类型                                       | 必填   | 说明             |
88e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- |
89e41f4b71Sopenharmony_ci| context | [Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md) | 是 | 表示应用上下文。 | 
90e41f4b71Sopenharmony_ci| bundleName | string   | 是    | 表示应用包名。 |
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**返回值:**
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| 类型               | 说明                |
95e41f4b71Sopenharmony_ci| ------------------ | ------------------- |
96e41f4b71Sopenharmony_ci| Promise\<[Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md)> | Promise对象。返回创建的Context。 |
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci**错误码:**
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci| 错误码ID | 错误信息        |
103e41f4b71Sopenharmony_ci| -------- | --------------- |
104e41f4b71Sopenharmony_ci| 201 | Permission denied. |
105e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api.|
106e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**示例:**
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci```ts
112e41f4b71Sopenharmony_ciimport { UIAbility, application} from '@kit.AbilityKit';
113e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility {
116e41f4b71Sopenharmony_ci  onCreate() {
117e41f4b71Sopenharmony_ci    let moduleContext: common.Context;
118e41f4b71Sopenharmony_ci    try {
119e41f4b71Sopenharmony_ci      application.createBundleContext(this.context, 'bundlename').then((data: Context)=>{
120e41f4b71Sopenharmony_ci        moduleContext = data;
121e41f4b71Sopenharmony_ci        console.info('createBundleContext success!');
122e41f4b71Sopenharmony_ci      }).catch((error : BusinessError)=>{
123e41f4b71Sopenharmony_ci        console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
124e41f4b71Sopenharmony_ci      })
125e41f4b71Sopenharmony_ci    } catch (error) {
126e41f4b71Sopenharmony_ci      console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
127e41f4b71Sopenharmony_ci    }
128e41f4b71Sopenharmony_ci  }
129e41f4b71Sopenharmony_ci}
130e41f4b71Sopenharmony_ci```