import { promptAction } from '@kit.ArkUI';
import { resourceManager } from '@kit.LocalizationKit';
@Entry
@Component
struct Index {
getDeviceTypeInfo(): string {
const
deviceType = getContext().resourceManager.getDeviceCapabilitySync().deviceType;
switch (deviceType) {
case resourceManager.DeviceType.DEVICE_TYPE_PHONE:
return "手机";
case resourceManager.DeviceType.DEVICE_TYPE_TABLET:
return "平板";
case resourceManager.DeviceType.DEVICE_TYPE_PC:
return "电脑";
case resourceManager.DeviceType.DEVICE_TYPE_TV:
return "电视";
case resourceManager.DeviceType.DEVICE_TYPE_CAR:
return "汽车";
case resourceManager.DeviceType.DEVICE_TYPE_WEARABLE:
return "穿戴";
case resourceManager.DeviceType.DEVICE_TYPE_2IN1:
return "2IN1";
default:
return "未知"
}
}
build() {
Column() {
Button('获取当前设备类型').onClick(() => {
promptAction.showToast({
message: this.getDeviceTypeInfo()
})
})
}
.height('100%')
.width('100%')
}
}
判断是不是折叠屏
import display from '@ohos.display';
@Entry
@Component
struct Index {
@State isFoldable: boolean = false
aboutToAppear(): void {
this.isFoldable = display.isFoldable() //是否是折叠屏
}
build() {
Column() {
Text(this.isFoldable + '')
}
}
}
鸿蒙判断当前设备的类型
于 2024-08-03 15:00:03 首次发布