通过API异步获取系统信息属性

通过API异步获取系统信息属性

HarmonyOS
2024-08-07 10:15:18
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
e_lion
// getSystemInfo.ets
import { atomicService } from '@kit.ScenarioFusionKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

let stateArray:Array<atomicService.SystemInfoType> = ['brand','deviceModel','screenWidth','screenHeight','statusBarHeight','screenSafeArea', 'language',
'osFullName', 'fontSizeSetting', 'sdkApiVersion', 'bluetoothEnabled', 'wifiEnabled', 'locationEnabled', 'deviceOrientation', 'theme', 'windowWidth', 'windowHeight']
try {
  atomicService.getSystemInfo(stateArray).then((data: atomicService.SystemInfo) => {
    hilog.info(0x0000, 'testTag', 'succeeded in getting system info asynchronously');
    let brand : string | undefined = data.brand;
    let deviceModel : string | undefined = data.deviceModel;
    let screenWidth : number | undefined = data.screenWidth;
    let screenHeight : number | undefined = data.screenHeight;
    let statusBarHeight : number | undefined = data.statusBarHeight;
    let screenSafeArea : window.AvoidArea | undefined = data.screenSafeArea;
    let language : string | undefined = data.language;
    let osFullName : string | undefined = data.osFullName;
    let fontSizeSetting : number | undefined = data.fontSizeSetting;
    let sdkApiVersion : number | undefined = data.sdkApiVersion;
    let bluetoothEnabled : boolean | undefined = data.bluetoothEnabled;
    let wifiEnabled : boolean | undefined = data.wifiEnabled;
    let locationEnabled : boolean | undefined = data.locationEnabled;
    let deviceOrientation : string | undefined = data.deviceOrientation;
    let theme : ColorMode | undefined = data.theme;
    let windowWidth : number | undefined = data.windowWidth;
    let windowHeight : number | undefined = data.windowHeight;
  }).catch((error : BusinessError) => {
    hilog.error(0x0000, 'testTag', 'Promise error: %{public}d %{public}s', error.code, error.message);
  })
} catch (error) {
  hilog.error(0x0000, 'testTag', 'failReason: %{public}d %{public}s', error.code, error.message);
}
分享
微博
QQ
微信
回复
2024-08-07 15:09:26
相关问题
通过API获取系统信息属性
313浏览 • 1回复 待解决
通过API获取系统设置属性
424浏览 • 1回复 待解决
如何获取组件的属性信息
1967浏览 • 1回复 待解决
HarmonyOS 系统信息获取方式
597浏览 • 1回复 待解决
targetsdkversion如何通过api获取
1584浏览 • 1回复 待解决
鸿蒙系统获取GPS相关信息
3872浏览 • 1回复 待解决
求教获取鸿蒙系统内存信息
7045浏览 • 1回复 待解决
api异步方法提供同步api需求
245浏览 • 1回复 待解决
如何获取鸿蒙系统手机相关信息
19206浏览 • 2回复 待解决
获取HarmonyOS系统版本的api
370浏览 • 1回复 待解决
应用通过什么接口获取设备标识信息
1721浏览 • 1回复 待解决
获取手机系统api版本是几
455浏览 • 1回复 待解决