• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import Configuration from '@ohos.app.ability.Configuration';
13```
14
15**System capability**: SystemCapability.Ability.AbilityBase
16
17  | Name| Type| Readable| Writable| Description|
18| -------- | -------- | -------- | -------- | -------- |
19| language | string | Yes| Yes| Language of the application, for example, **zh**.|
20| colorMode | [ColorMode](js-apis-app-ability-configurationConstant.md#configurationconstantcolormode) | Yes| Yes| Color mode. The default value is **COLOR_MODE_LIGHT**. The options are as follows:<br>- **COLOR_MODE_NOT_SET**: The color mode is not set.<br>- **COLOR_MODE_LIGHT**: light mode.<br>- **COLOR_MODE_DARK**: dark mode.|
21| direction | [Direction](js-apis-app-ability-configurationConstant.md#configurationconstantdirection) | Yes| No| Screen orientation. The options are as follows:<br>- **DIRECTION_NOT_SET**: The screen orientation is not set.<br>- **DIRECTION_HORIZONTAL**: horizontal direction.<br>- **DIRECTION_VERTICAL**: vertical direction.|
22| screenDensity  | [ScreenDensity](js-apis-app-ability-configurationConstant.md#configurationconstantscreendensity) | Yes| No| Pixel density of the screen. The options are as follows:<br>- **SCREEN_DENSITY_NOT_SET**: The pixel density is not set.<br>- **SCREEN_DENSITY_SDPI**: 120.<br>- **SCREEN_DENSITY_MDPI**: 160.<br>- **SCREEN_DENSITY_LDPI**: 240.<br>- **SCREEN_DENSITY_XLDPI**: 320.<br>- **SCREEN_DENSITY_XXLDPI**: 480.<br>- **SCREEN_DENSITY_XXXLDPI**: 640.|
23| displayId  | number | Yes| No| ID of the display where the application is located.|
24| hasPointerDevice  | boolean | Yes| No| Whether a pointer device, such as a keyboard, mouse, or touchpad, is connected.|
25
26For details about the fields, see the **ohos.app.ability.Configuration.d.ts** file.
27
28**Example**
29
30  ```ts
31  import UIAbility from '@ohos.app.ability.UIAbility';
32
33  export default class EntryAbility extends UIAbility {
34    onCreate(want, launchParam) {
35      let envCallback = {
36        onConfigurationUpdated(config) {
37          console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
38          let language = config.language;
39          let colorMode = config.colorMode;
40          let direction = config.direction;
41          let screenDensity = config.screenDensity;
42          let displayId = config.displayId;
43          let hasPointerDevice = config.hasPointerDevice;
44        }
45      };
46      try {
47        let applicationContext = this.context.getApplicationContext();
48        let callbackId = applicationContext.on('environment', envCallback);
49        console.log('callbackId: ' + callbackId);
50      } catch (paramError) {
51        console.log('error: ' + paramError.code + ', ' + paramError.message);
52      }
53    }
54  }
55  ```
56