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 '@kit.AbilityKit'; 13``` 14 15## Properties 16 17**System capability**: SystemCapability.Ability.AbilityBase 18 19| Name| Type| Read-only| Optional| Description| 20| -------- | -------- | -------- | -------- | -------- | 21| language | string | No| Yes| Language of the application, for example, **zh**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 22| colorMode | [ConfigurationConstant.ColorMode](js-apis-app-ability-configurationConstant.md#colormode) | No| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 23| direction | [ConfigurationConstant.Direction](js-apis-app-ability-configurationConstant.md#direction) | No| Yes| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 24| screenDensity | [ConfigurationConstant.ScreenDensity](js-apis-app-ability-configurationConstant.md#screendensity) | No| Yes| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 25| displayId | number | No| Yes| ID of the display where the application is located.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 26| hasPointerDevice | boolean | No| Yes| Whether a pointer device, such as a keyboard, mouse, or touchpad, is connected.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 27| fontId<sup>14+<sup> | number | No| Yes| Unique ID of the current system font.<br>**Atomic service API**: This API can be used in atomic services since API version 14.| 28| fontSizeScale<sup>12+<sup> | number | No| Yes| Font size scale ratio. The value is a non-negative number. The default value is **1**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 29| fontWeightScale<sup>12+<sup> | number | No| Yes| Font weight scale ratio. The value is a non-negative number. The default value is **1**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 30| mcc<sup>12+<sup> | string | No | Yes| Mobile network code (MNC).<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 31| mnc<sup>12+<sup> | string | No | Yes| Mobile country code (MCC).<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 32 33**Example** 34 35```ts 36import { UIAbility, AbilityConstant, EnvironmentCallback, Want } from '@kit.AbilityKit'; 37import { BusinessError } from '@kit.BasicServicesKit'; 38 39export default class EntryAbility extends UIAbility { 40 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 41 let envCallback: EnvironmentCallback = { 42 onConfigurationUpdated(config) { 43 console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`); 44 let language = config.language; 45 let colorMode = config.colorMode; 46 let direction = config.direction; 47 let screenDensity = config.screenDensity; 48 let displayId = config.displayId; 49 let hasPointerDevice = config.hasPointerDevice; 50 let fontId = config.fontId; 51 let fontSizeScale = config.fontSizeScale; 52 let fontWeightScale = config.fontWeightScale; 53 let mcc = config.mcc; 54 let mnc = config.mnc; 55 }, 56 onMemoryLevel(level) { 57 console.log(`onMemoryLevel level: ${level}`); 58 } 59 }; 60 try { 61 let applicationContext = this.context.getApplicationContext(); 62 let callbackId = applicationContext.on('environment', envCallback); 63 console.log(`callbackId: ${callbackId}`); 64 } catch (paramError) { 65 console.error(`error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`); 66 } 67 } 68} 69``` 70