• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.application.Configuration (Configuration)
2
3The **Configuration** module defines environment change information. **Configuration** is an interface definition and is used only for field declaration.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> This module is deprecated since API version 9. You are advised to use [@ohos.app.ability.Configuration](js-apis-app-ability-configuration.md) instead.
9
10## Modules to Import
11
12```ts
13import Configuration from '@ohos.application.Configuration';
14```
15
16## Attributes
17
18**System capability**: SystemCapability.Ability.AbilityBase
19
20  | Name| Type| Readable| Writable| Description|
21| -------- | -------- | -------- | -------- | -------- |
22| language<sup>8+</sup> | string | Yes| Yes| Language of the application, for example, **zh**.|
23| colorMode<sup>8+</sup> | [ColorMode](js-apis-application-configurationConstant.md#configurationconstantcolormode) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.|
24
25For details about the fields, see the **ohos.application.Configuration.d.ts** file.
26
27**Example**
28  ```ts
29import UIAbility from '@ohos.app.ability.UIAbility';
30import AbilityConstant from '@ohos.app.ability.AbilityConstant';
31import EnvironmentCallback from '@ohos.app.ability.EnvironmentCallback';
32import Want from '@ohos.app.ability.Want';
33import Window from '@ohos.window';
34
35export default class EntryAbility extends UIAbility {
36    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
37    }
38
39    onDestroy() {
40    }
41
42    onWindowStageCreate(windowStage: Window.WindowStage) {
43        let envCallback: EnvironmentCallback = {
44            onConfigurationUpdated(config) {
45                console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
46                let language = config.language;
47                let colorMode = config.colorMode;
48            },
49            onMemoryLevel(level){
50                console.log(`onMemoryLevel level: ${JSON.stringify(level)}`);
51            }
52        };
53
54        let applicationContext = this.context.getApplicationContext();
55        applicationContext.on('environment',envCallback);
56
57        windowStage.loadContent('pages/index', (err, data) => {
58            if (err.code) {
59                console.error(`failed to load the content, error: ${JSON.stringify(err)}`);
60                return;
61            }
62            console.info(`Succeeded in loading the content, data: ${JSON.stringify(data)}`);
63        });
64    }
65}
66  ```
67