当前位置:网站首页>Open Source Summer | How OpenHarmony Query Device Type (eTS)
Open Source Summer | How OpenHarmony Query Device Type (eTS)
2022-08-05 09:32:00 【InfoQ】
- 通过jsInterface query to specify system parameters(const.build.characteristics)to determine the device type,详见系统属性.
// @ts-nocheck
import parameter from '@ohos.systemParameter'
@Entry
@Component
struct GetDeviceTypeSample {
@State deviceType: string = 'unknown';
build() {
Column() {
Text("获取设备类型").fontSize(24)
Text(this.deviceType).fontSize(24).onClick(()=>{
try {
this.deviceType = parameter.getSync("const.build.characteristics");
} catch(e) {
console.log("getSync unexpected error: " + e);
}
})
}
.width('100%')
.height('100%')
}
}
// @ts-nocheck
/*
* Copyright (c) 2021 JianGuo Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import parameter from '@ohos.systemParameter'
@Entry
@Component
struct GetDeviceTypeSample {
@State deviceType: string = 'unknown';
build() {
Column() {
Text("获取设备类型").fontSize(24)
//通过jsInterface query to specify system parameters(const.build.characteristics)to determine the device type
Text(this.deviceType).fontSize(24).onClick(()=>{
try {
this.deviceType = parameter.getSync("const.build.characteristics");
} catch(e) {
console.log("getSync unexpected error: " + e);
}
})
//通过deviceInfo查询设备类型
Text(this.deviceType).fontSize(24).onClick(()=>{
try {
this.deviceType= deviceInfo.deviceType;
} catch(e) {
console.log("getSync unexpected error: " + e);
}
})
//通过displayQuery the properties of the display device(Including screen width、high and screen density, etc.)
Text(this.deviceType).fontSize(24).onClick(()=>{
display.getDefaultDisplay()
.then((displayInfo) => {
console.info('Display width: '+ displayInfo.width);
console.info('Display height: '+ displayInfo.height);
console.info('Display density: '+ displayInfo.densityDPI);
})
.catch((error) => {
console.error('Failed to obtain the default display size. Cause: '+JSON.stringify(error));
})
})
}
.width('100%')
.height('100%')
}
}
How to query the screen/窗口尺寸
- 通过displayQuery the properties of the display device(Including screen width、high and screen density, etc.),详见屏幕属性.
// @ts-nocheck
/*
* Copyright (c) 2021 JianGuo Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import deviceInfo from'@ohos.deviceInfo'
import parameter from '@ohos.systemParameter'
import display from '@ohos.display';
@Entry
@Component
struct GetDeviceTypeSample {
@State deviceType: string = 'deviceType';
@State device: string = 'device';
@State displayInfo: string = 'displayInfo';
aboutToAppear() {
try {
this.deviceType = parameter.getSync("const.build.characteristics");
} catch(e) {
console.log("getSync unexpected error: " + e);
}
}
build() {
Column() {
Text("设备属性").fontSize(36)
//通过jsInterface query to specify system parameters(const.build.characteristics)to determine the device type
Text(this.deviceType).fontSize(28).onClick(() => {
try {
this.deviceType = parameter.getSync("const.build.characteristics");
console.log("坚果"
+
this.deviceType);
} catch (e) {
console.log("getSync unexpected error: " + e);
}
})
//通过deviceInfo查询设备类型
Text( this.device).fontSize(28).onClick(() => {
this.device= deviceInfo.deviceType;
})
//通过displayQuery the properties of the display device(Including screen width、high and screen density, etc.)
Text(this.displayInfo).fontSize(28).onClick(() => {
display.getDefaultDisplay()
.then((displayInfo) => {
console.info('Display width: ' + displayInfo.width);
console.info('Display height: ' + displayInfo.height);
console.info('Display density: ' + displayInfo.densityDPI);
this.displayInfo=JSON.stringify(displayInfo);
console.info('Display density: ' + JSON.stringify(displayInfo));
})
.catch((error) => {
console.error('Failed to obtain the default display size. Cause: ' + JSON.stringify(error));
})
})
}
.width('100%')
.height('100%').justifyContent(FlexAlign.Center).alignItems(HorizontalAlign.Center)
}
}
{"alive":true,"densityDPI":560,"densityPixels":3.5,"height":2560,"id":0,"name":"内置屏幕","refreshRate":60.000004,"rotation":0,"scaledDensity":3.5,"state":2,"width":1440,"xDPI":560,"yDPI":560}
Display

边栏推荐
猜你喜欢

Creo 9.0 基准特征:基准点

C语言的高级用法

21 Days of Deep Learning - Convolutional Neural Networks (CNN): Weather Recognition (Day 5)

使用稀疏 4D 卷积对 3D LiDAR 数据中的运动对象进行后退分割(IROS 2022)

Example of Noise Calculation for Amplifier OPA855

ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...

sql server中 两表查询 平均数 分组

为什么我推荐使用智能化async?

营销建议 | 您有一份八月营销月历待查收! 建议收藏 !

C语言-数组
随机推荐
请问大佬们 ,使用 Flink SQL CDC 是不是做不到两个数据库的实时同步啊
程序员的七种武器
ffmpeg drawtext add text watermark
百行代码发射红心,程序员何愁命不中女朋友!
明天去订票,准备回家咯~~
Why do I recommend using smart async?
新白娘子传奇系列
七夕浪漫约会不加班,RPA机器人帮你搞定工作
ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...
tensorflow.keras无法引入layers
Creo 9.0 基准特征:基准轴
PAT Class B-B1019 Digital Black Hole (20)
Voice conversion相关语音数据集综合汇总
express hot-reload
openpyxl操作Excel文件
MySQL内部函数介绍
Tanabata romantic date without overtime, RPA robot helps you get the job done
【零基础玩转BLDC系列】无刷直流电机无位置传感器三段式启动法详细介绍及代码分享
放大器OPA855的噪声计算实例
Is there a problem with writing this?How to synchronize data in sql-client