未验证 提交 44b60327 编写于 作者: O openharmony_ci 提交者: Gitee

!13350 @ohos.app.ability.Configuration 示例代码修改

Merge pull request !13350 from gongyuechen/monthly_20221018
...@@ -16,10 +16,10 @@ import Configuration from '@ohos.app.ability.Configuration' ...@@ -16,10 +16,10 @@ import Configuration from '@ohos.app.ability.Configuration'
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| language | string | 是 | 是 | 表示应用程序的当前语言。 | | language | string | 是 | 是 | 表示应用程序的当前语言。例如:zh。 |
| colorMode | [ColorMode](js-apis-app-ability-configurationConstant.md#configurationconstantcolormode) | 是 | 是 | 表示深浅色模式,取值范围:浅色模式(COLOR_MODE_LIGHT),深色模式(COLOR_MODE_DARK)。默认为浅色。 | | colorMode | [ColorMode](js-apis-app-ability-configurationConstant.md#configurationconstantcolormode) | 是 | 是 | 表示深浅色模式,取值范围:浅色模式(COLOR_MODE_LIGHT),深色模式(COLOR_MODE_DARK)。默认为浅色。 |
| direction | Direction | 是 | 否 | 表示屏幕方向,取值范围:水平方向(DIRECTION_HORIZONTAL),垂直方向(DIRECTION_VERTICAL)。 | | direction | [Direction](js-apis-app-ability-configurationConstant.md#configurationconstantdirection) | 是 | 否 | 表示屏幕方向,取值范围:水平方向(DIRECTION_HORIZONTAL),垂直方向(DIRECTION_VERTICAL)。 |
| screenDensity | ScreenDensity | 是 | 否 | 表示屏幕分辨率,取值范围:SCREEN_DENSITY_SDPI(120)、SCREEN_DENSITY_MDPI(160)、SCREEN_DENSITY_LDPI(240)、SCREEN_DENSITY_XLDPI(320)、SCREEN_DENSITY_XXLDPI(480)、SCREEN_DENSITY_XXXLDPI(640)。 | | screenDensity | [ScreenDensity](js-apis-app-ability-configurationConstant.md#configurationconstantscreendensity) | 是 | 否 | 表示屏幕分辨率,取值范围:SCREEN_DENSITY_SDPI(120)、SCREEN_DENSITY_MDPI(160)、SCREEN_DENSITY_LDPI(240)、SCREEN_DENSITY_XLDPI(320)、SCREEN_DENSITY_XXLDPI(480)、SCREEN_DENSITY_XXXLDPI(640)。 |
| displayId | number | 是 | 否 | 表示应用所在的物理屏幕Id。 | | displayId | number | 是 | 否 | 表示应用所在的物理屏幕Id。 |
| hasPointerDevice | boolean | 是 | 否 | 指示指针类型设备是否已连接,如键鼠、触控板等。 | | hasPointerDevice | boolean | 是 | 否 | 指示指针类型设备是否已连接,如键鼠、触控板等。 |
...@@ -28,6 +28,10 @@ import Configuration from '@ohos.app.ability.Configuration' ...@@ -28,6 +28,10 @@ import Configuration from '@ohos.app.ability.Configuration'
**示例:** **示例:**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
let envCallback = { let envCallback = {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`) console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`)
...@@ -40,9 +44,12 @@ import Configuration from '@ohos.app.ability.Configuration' ...@@ -40,9 +44,12 @@ import Configuration from '@ohos.app.ability.Configuration'
} }
}; };
try { try {
var callbackId = applicationContext.on("environment", envCallback); let applicationContext = this.context.getApplicationContext();
let callbackId = applicationContext.on("environment", envCallback);
console.log("callbackId: " + callbackId);
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log("error: " + paramError.code + ", " + paramError.message);
} }
}
}
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册