以下是获取系统设置属性的接口说明,更多接口及使用方法请参见atomicService(融合场景化API)。
| 接口名 | 描述 |
|---|---|
| getSystemSetting(properties?: Array<SystemSettingType>): SystemSettingInfo | 获取系统设置属性的方法,支持获取蓝牙、定位、Wi-Fi开关信息,以及设备方向信息的请求对象。 |
导入Scenario Fusion Kit模块以及相关公共模块。
import { atomicService } from '@kit.ScenarioFusionKit';
import { hilog } from '@kit.PerformanceAnalysisKit'; 传入属性参数,调用接口获取对应属性值,代码如下:
let stateArray: atomicService.SystemSettingType[] =
['bluetoothEnabled', 'locationEnabled', 'deviceOrientation', 'wifiEnabled'];
try {
let data = atomicService.getSystemSetting(stateArray);
hilog.info(0x0000, 'testTag', 'succeeded in getting system setting info');
// 当前参数未调用,开发者自行实现参数的逻辑处理
let bluetoothEnabled: boolean | undefined = data.bluetoothEnabled;
let locationEnabled: boolean | undefined = data.locationEnabled;
let deviceOrientation: string | undefined = data.deviceOrientation;
let wifiEnabled: boolean | undefined = data.wifiEnabled;
} catch (error) {
hilog.error(0x0001, 'testTag', 'Failed to get system setting info, failReason: %{public}d %{public}s', error.code, error.message);
}