index.uts 982 字节
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import { DeviceUtil } from './device/DeviceUtil.uts';

import { GetSystemSetting, GetSystemSettingResult } from '../interface.uts'
import Exception from 'java.lang.Exception';

export const getSystemSetting : GetSystemSetting = () : GetSystemSettingResult => {
	let context = UTSAndroid.getAppContext();
	let result : GetSystemSettingResult = {
		deviceOrientation : DeviceUtil.deviceOrientation(context!),
		locationEnabled : DeviceUtil.locationEnable(context!),
	};
	try {
		let blueToothEnable = DeviceUtil.blueToothEnable(context!);
		result.bluetoothEnabled = blueToothEnable;
	} catch (e : Exception) {
		result.bluetoothError = "Missing permissions required by BluetoothAdapter.isEnabled: android.permission.BLUETOOTH";
	}

	try {
		result.wifiEnabled = DeviceUtil.wifiEnable(context!);
	} catch (e : Exception) {
		result.wifiError = "Missing permissions required by WifiManager.isWifiEnabled: android.permission.ACCESS_WIFI_STATE";
	}
	return result;
}