openharmony 鸿蒙 js-apis-app-ability-configuration

2025-06-12 浏览 (1)

@ohos.app.ability.Configuration (Configuration)

The Configuration module defines environment change information. Configuration is an interface definition and is used only for field declaration.

NOTE

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.

Modules to Import

import { Configuration } from '@kit.AbilityKit';

Properties

System capability: SystemCapability.Ability.AbilityBase

NameTypeRead-onlyOptionalDescription
languagestringNoYesLanguage of the application, for example, zh.
Atomic service API: This API can be used in atomic services since API version 11.
colorModeConfigurationConstant.ColorModeNoYesColor mode. The default value is COLOR_MODE_LIGHT. The options are as follows:
- COLOR_MODE_NOT_SET: The color mode is not set.
- COLOR_MODE_LIGHT: light mode.
- COLOR_MODE_DARK: dark mode.
Atomic service API: This API can be used in atomic services since API version 11.
directionConfigurationConstant.DirectionNoYesScreen orientation. The options are as follows:
- DIRECTION_NOT_SET: The screen orientation is not set.
- DIRECTION_HORIZONTAL: horizontal direction.
- DIRECTION_VERTICAL: vertical direction.
Atomic service API: This API can be used in atomic services since API version 11.
screenDensityConfigurationConstant.ScreenDensityNoYesPixel density of the screen. The options are as follows:
- SCREEN_DENSITY_NOT_SET: The pixel density is not set.
- SCREEN_DENSITY_SDPI: 120.
- SCREEN_DENSITY_MDPI: 160.
- SCREEN_DENSITY_LDPI: 240.
- SCREEN_DENSITY_XLDPI: 320.
- SCREEN_DENSITY_XXLDPI: 480.
- SCREEN_DENSITY_XXXLDPI: 640.
Atomic service API: This API can be used in atomic services since API version 11.
displayIdnumberNoYesID of the display where the application is located.
Atomic service API: This API can be used in atomic services since API version 11.
hasPointerDevicebooleanNoYesWhether a pointer device, such as a keyboard, mouse, or touchpad, is connected. The value true means that the pointer device is connected, and false means the opposite.
Atomic service API: This API can be used in atomic services since API version 11.
fontId14+stringNoYesUnique ID of the current system font.
Atomic service API: This API can be used in atomic services since API version 14.
fontSizeScale12+numberNoYesFont size scale ratio. The value is a non-negative number. The default value is 1.
Atomic service API: This API can be used in atomic services since API version 12.
fontWeightScale12+numberNoYesFont weight scale ratio. The value is a non-negative number. The default value is 1.
Atomic service API: This API can be used in atomic services since API version 12.
mcc12+stringNoYesMobile network code (MNC).
Atomic service API: This API can be used in atomic services since API version 12.
mnc12+stringNoYesMobile country code (MCC).
Atomic service API: This API can be used in atomic services since API version 12.
locale20+Intl.LocaleNoYesLocale. The application automatically adjusts its behavior based on the current locale to meet the localization requirements of users. This property can be set by configuring the system language, system region, and application preferred language.
Atomic service API: This API can be used in atomic services since API version 20.

Example

import { UIAbility, AbilityConstant, EnvironmentCallback, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
    let envCallback: EnvironmentCallback = {
      onConfigurationUpdated(config) {
        console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
        let language = config.language;
        let colorMode = config.colorMode;
        let direction = config.direction;
        let screenDensity = config.screenDensity;
        let displayId = config.displayId;
        let hasPointerDevice = config.hasPointerDevice;
        let fontId = config.fontId;
        let fontSizeScale = config.fontSizeScale;
        let fontWeightScale = config.fontWeightScale;
        let mcc = config.mcc;
        let mnc = config.mnc;
        let locale = config.locale;
      },
      onMemoryLevel(level) {
        console.log(`onMemoryLevel level: ${level}`);
      }
    };
    try {
      let applicationContext = this.context.getApplicationContext();
      let callbackId = applicationContext.on('environment', envCallback);
      console.log(`callbackId: ${callbackId}`);
    } catch (paramError) {
      console.error(`error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`);
    }
  }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/qem5W5