本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口仅可在Stage模型下使用。
Context模块提供了ability或application的上下文的能力,包括访问特定应用程序的资源等。
本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口仅可在Stage模型下使用。
系统能力:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
名称 | 类型 | 可读 | 可写 | 说明 |
---|---|---|---|---|
resourceManager | resmgr.ResourceManager | 是 | 否 | 资源管理对象。 |
applicationInfo | 是 | 否 | 当前应用程序的信息。 | |
cacheDir | string | 是 | 否 | 缓存目录。 |
tempDir | string | 是 | 否 | 临时目录。 |
filesDir | string | 是 | 否 | 文件目录。 |
databaseDir | string | 是 | 否 | 数据库目录。 |
preferencesDir | string | 是 | 否 | preferences目录。 |
bundleCodeDir | string | 是 | 否 | 安装包目录。不能拼接路径访问资源文件,请使用资源管理接口访问资源。 |
distributedFilesDir | string | 是 | 否 | 分布式文件目录。 |
eventHub | 是 | 否 | 事件中心,提供订阅、取消订阅、触发事件对象。 | |
area | 是 | 否 | 文件分区信息。 |
createModuleContext(moduleName: string): Context;
根据模块名创建上下文Context。
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
moduleName | string | 是 | 模块名。 |
返回值:
类型 | 说明 |
---|---|
Context | 上下文Context。 |
示例:
let moduleContext = this.context.createModuleContext('entry');
getApplicationContext(): ApplicationContext;
获取应用上下文Context。
系统能力:SystemCapability.Ability.AbilityRuntime.Core
返回值:
类型 | 说明 |
---|---|
Context | 应用上下文Context。 |
示例:
let applicationContext = this.context.getApplicationContext();
文件分区
系统能力:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
名称 | 值 | 说明 |
---|---|---|
EL1 | 0 | 设备级加密区,设备开机后可访问的数据区。 |
EL2 | 1 | 用户级加密区,设备开机,首次输入密码后才能够访问的数据区。 |