Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
c9126d29
U
uni-api
项目概览
DCloud
/
uni-api
通知
689
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c9126d29
编写于
10月 30, 2023
作者:
DCloud-yyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
开源:uni.getSystemSetting
上级
78c7d4d5
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
276 addition
and
0 deletion
+276
-0
uni_modules/uni-getSystemSetting/changelog.md
uni_modules/uni-getSystemSetting/changelog.md
+0
-0
uni_modules/uni-getSystemSetting/package.json
uni_modules/uni-getSystemSetting/package.json
+93
-0
uni_modules/uni-getSystemSetting/readme.md
uni_modules/uni-getSystemSetting/readme.md
+5
-0
uni_modules/uni-getSystemSetting/utssdk/app-android/device/DeviceUtil.uts
...getSystemSetting/utssdk/app-android/device/DeviceUtil.uts
+60
-0
uni_modules/uni-getSystemSetting/utssdk/app-android/index.uts
...modules/uni-getSystemSetting/utssdk/app-android/index.uts
+26
-0
uni_modules/uni-getSystemSetting/utssdk/app-ios/index.uts
uni_modules/uni-getSystemSetting/utssdk/app-ios/index.uts
+31
-0
uni_modules/uni-getSystemSetting/utssdk/interface.uts
uni_modules/uni-getSystemSetting/utssdk/interface.uts
+61
-0
未找到文件。
uni_modules/uni-getSystemSetting/changelog.md
0 → 100644
浏览文件 @
c9126d29
uni_modules/uni-getSystemSetting/package.json
0 → 100644
浏览文件 @
c9126d29
{
"id"
:
"uni-getSystemSetting"
,
"displayName"
:
"uni-getSystemSetting"
,
"version"
:
"1.0.0"
,
"description"
:
"uni-getSystemSetting"
,
"keywords"
:
[
"uni-getSystemSetting"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.6.8"
},
"dcloudext"
:
{
"type"
:
"uts"
,
"sale"
:
{
"regular"
:
{
"price"
:
"0.00"
},
"sourcecode"
:
{
"price"
:
"0.00"
}
},
"contact"
:
{
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
},
"npmurl"
:
""
},
"uni_modules"
:
{
"dependencies"
:
[],
"uni-ext-api"
:
{
"uni"
:
{
"getSystemSetting"
:
{
"name"
:
"getSystemSetting"
,
"app"
:
{
"js"
:
false
,
"kotlin"
:
true
,
"swift"
:
true
}
}
}
},
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"u"
,
"aliyun"
:
"u"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"u"
,
"vue3"
:
"u"
},
"App"
:
{
"app-android"
:
"u"
,
"app-ios"
:
"u"
},
"H5-mobile"
:
{
"Safari"
:
"u"
,
"Android Browser"
:
"u"
,
"微信浏览器(Android)"
:
"u"
,
"QQ浏览器(Android)"
:
"u"
},
"H5-pc"
:
{
"Chrome"
:
"u"
,
"IE"
:
"u"
,
"Edge"
:
"u"
,
"Firefox"
:
"u"
,
"Safari"
:
"u"
},
"小程序"
:
{
"微信"
:
"u"
,
"阿里"
:
"u"
,
"百度"
:
"u"
,
"字节跳动"
:
"u"
,
"QQ"
:
"u"
,
"钉钉"
:
"u"
,
"快手"
:
"u"
,
"飞书"
:
"u"
,
"京东"
:
"u"
},
"快应用"
:
{
"华为"
:
"u"
,
"联盟"
:
"u"
}
}
}
}
}
\ No newline at end of file
uni_modules/uni-getSystemSetting/readme.md
0 → 100644
浏览文件 @
c9126d29
# uni-getSystemSetting
### 开发文档
[
UTS 语法
](
https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html
)
[
UTS 原生插件
](
https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
)
[
Hello UTS
](
https://gitcode.net/dcloud/hello-uts/-/tree/dev
)
\ No newline at end of file
uni_modules/uni-getSystemSetting/utssdk/app-android/device/DeviceUtil.uts
0 → 100644
浏览文件 @
c9126d29
import WifiManager from 'android.net.wifi.WifiManager';
import Configuration from 'android.content.res.Configuration';
import Context from 'android.content.Context';
import LocationManager from 'android.location.LocationManager';
import BluetoothManager from 'android.bluetooth.BluetoothManager';
import PackageManager from 'android.content.pm.PackageManager';
import Manifest from 'android.Manifest';
import Build from 'android.os.Build';
import Settings from 'android.provider.Settings';
export class DeviceUtil{
/**
* 设备蓝牙是否开启
* @param context .
* @return .
* @throws Exception 如果没开启蓝牙权限就有异常
*/
public static blueToothEnable(context: Context): boolean {
if (Build.VERSION.SDK_INT >= 23 && context.checkSelfPermission(Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_DENIED) {
throw new Exception();
}
let bluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager;
let defaultAdapter = bluetoothManager.getAdapter();
return defaultAdapter.isEnabled();
}
public static locationEnable(context: Context): boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){
let locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager;
if (locationManager == null) {
return false;
}
return locationManager.isLocationEnabled();
}else{
const mode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE,
Settings.Secure.LOCATION_MODE_OFF);
return (mode != Settings.Secure.LOCATION_MODE_OFF);
}
}
public static wifiEnable(context: Context): boolean {
let wifiManager = context.getApplicationContext().getSystemService(Context.WIFI_SERVICE) as WifiManager;
let wifiState = wifiManager.getWifiState();
return wifiState == WifiManager.WIFI_STATE_ENABLED;
}
public static deviceOrientation(context: Context): string {
let configuration = context.getResources().getConfiguration();
let orientation = configuration.orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
return "portrait";
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
return "landscape";
}
return "";
}
}
\ No newline at end of file
uni_modules/uni-getSystemSetting/utssdk/app-android/index.uts
0 → 100644
浏览文件 @
c9126d29
import { UTSAndroid } from "io.dcloud.uts";
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;
}
\ No newline at end of file
uni_modules/uni-getSystemSetting/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
c9126d29
import { GetSystemSetting, GetSystemSettingResult } from '../interface.uts'
import { UTSiOS } from "DCloudUTSFoundation";
export const getSystemSetting : GetSystemSetting = () : GetSystemSettingResult => {
let setting : Map<string, any> = UTSiOS.getSystemSetting();
let result : GetSystemSettingResult = {
deviceOrientation: "portrait",
locationEnabled : false
};
if (setting.has("bluetoothEnabled")) {
result.bluetoothEnabled = setting.get("bluetoothEnabled") as boolean;
}
if (setting.has("bluetoothError")) {
result.bluetoothError = setting.get("bluetoothError") as string;
}
if (setting.has("locationEnabled")) {
result.locationEnabled = setting.get("locationEnabled") as boolean;
}
if (setting.has("wifiEnabled")) {
result.wifiEnabled = setting.get("wifiEnabled") as boolean;
}
if (setting.has("deviceOrientation")) {
result.deviceOrientation = setting.get("deviceOrientation") as string;
}
return result;
}
\ No newline at end of file
uni_modules/uni-getSystemSetting/utssdk/interface.uts
0 → 100644
浏览文件 @
c9126d29
export type GetSystemSettingResult = {
/**
* 蓝牙是否开启
*/
bluetoothEnabled?: boolean,
/**
* 蓝牙的报错信息
*/
bluetoothError?: string,
/**
* 位置是否开启
*/
locationEnabled : boolean,
/**
* wifi是否开启
*/
wifiEnabled?: boolean,
/**
* wifi的报错信息
*/
wifiError?: string,
/**
* 设备方向
*/
deviceOrientation : string
}
export type GetSystemSetting = () => GetSystemSettingResult
export interface Uni {
/**
* GetSystemSetting()
* @description
* 获取系统设置
* @return {object}
* @tutorial https://uniapp.dcloud.net.cn/api/system/getsystemsetting.html
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4",
* "uniVer": "√",
* "unixVer": "3.9+"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
* "unixVer": "3.9+"
* }
* }
* }
* @example
```typescript
uni.getSystemSetting()
```
*/
getSystemSetting(): GetSystemSettingResult;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录