1e41f4b71Sopenharmony_ci# @ohos.application.Configuration (Configuration)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci定义环境变化信息。Configuration是接口定义,仅做字段声明。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> 本模块从API version 9废弃,替换模块为[@ohos.app.ability.Configuration (Configuration)](js-apis-app-ability-configuration.md)
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 导入模块
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport Configuration from '@ohos.application.Configuration';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## 属性
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci  | 名称 | 类型 | 可读 | 可写 | 说明 |
21e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
22e41f4b71Sopenharmony_ci| language<sup>8+</sup> | string | 是 | 是 | 表示应用程序的当前语言。例如:zh。 |
23e41f4b71Sopenharmony_ci| colorMode<sup>8+</sup> | [ConfigurationConstant.ColorMode](js-apis-application-configurationConstant.md#colormode) | 是 | 是 | 表示深浅色模式,取值范围:浅色模式(COLOR_MODE_LIGHT),深色模式(COLOR_MODE_DARK)。默认为浅色。 |
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci具体字段描述参考ohos.application.Configuration.d.ts文件
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**示例:**
28e41f4b71Sopenharmony_ci  ```ts
29e41f4b71Sopenharmony_ciimport UIAbility from '@ohos.app.ability.UIAbility';
30e41f4b71Sopenharmony_ciimport AbilityConstant from '@ohos.app.ability.AbilityConstant';
31e41f4b71Sopenharmony_ciimport EnvironmentCallback from '@ohos.app.ability.EnvironmentCallback';
32e41f4b71Sopenharmony_ciimport Want from '@ohos.app.ability.Want';
33e41f4b71Sopenharmony_ciimport Window from '@ohos.window';
34e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility {
37e41f4b71Sopenharmony_ci    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
38e41f4b71Sopenharmony_ci    }
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci    onDestroy() {
41e41f4b71Sopenharmony_ci    }
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci    onWindowStageCreate(windowStage: Window.WindowStage) {
44e41f4b71Sopenharmony_ci        let envCallback: EnvironmentCallback = {
45e41f4b71Sopenharmony_ci            onConfigurationUpdated(config) {
46e41f4b71Sopenharmony_ci                console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
47e41f4b71Sopenharmony_ci                let language = config.language;
48e41f4b71Sopenharmony_ci                let colorMode = config.colorMode;
49e41f4b71Sopenharmony_ci            },
50e41f4b71Sopenharmony_ci            onMemoryLevel(level){
51e41f4b71Sopenharmony_ci                console.log(`onMemoryLevel level: ${JSON.stringify(level)}`);
52e41f4b71Sopenharmony_ci            }
53e41f4b71Sopenharmony_ci        };
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci        let applicationContext = this.context.getApplicationContext();
56e41f4b71Sopenharmony_ci        try {
57e41f4b71Sopenharmony_ci            applicationContext.on('environment',envCallback);
58e41f4b71Sopenharmony_ci        } catch (paramError) {
59e41f4b71Sopenharmony_ci            console.error(`error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`);
60e41f4b71Sopenharmony_ci        }
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci        windowStage.loadContent('pages/index', (err, data) => {
63e41f4b71Sopenharmony_ci            if (err.code) {
64e41f4b71Sopenharmony_ci                console.error(`failed to load the content, error: ${JSON.stringify(err)}`);
65e41f4b71Sopenharmony_ci                return;
66e41f4b71Sopenharmony_ci            }
67e41f4b71Sopenharmony_ci            console.info(`Succeeded in loading the content, data: ${JSON.stringify(data)}`);
68e41f4b71Sopenharmony_ci        });
69e41f4b71Sopenharmony_ci    }
70e41f4b71Sopenharmony_ci}
71e41f4b71Sopenharmony_ci  ```
72e41f4b71Sopenharmony_ci
73