Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
cfdc2863
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
cfdc2863
编写于
7月 05, 2024
作者:
DCloud-yyl
提交者:
DCloud-WZF
7月 08, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
同步uni-getbatteryinfo插件代码
上级
64bb5e6d
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
237 addition
and
210 deletion
+237
-210
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
+60
-67
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
+35
-34
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
+108
-109
uni_modules/uni-getbatteryinfo/utssdk/unierror.uts
uni_modules/uni-getbatteryinfo/utssdk/unierror.uts
+34
-0
未找到文件。
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
浏览文件 @
cfdc2863
import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess, GetBatteryInfoResult,
GetBatteryInfoSync } from '../interface.uts'
import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess, GetBatteryInfoResult,
GetBatteryInfoSync } from '../interface.uts'
import IntentFilter from 'android.content.IntentFilter';
import Intent from 'android.content.Intent';
import { GetBatteryInfoFailImpl } from '../unierror';
/**
* 异步获取电量
*/
export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
...
...
@@ -34,21 +33,18 @@ export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInf
options.success?.(res)
options.complete?.(res)
} else {
const res = new UniError("uni-getBatteryInfo", 1001, "getBatteryInfo:fail getAppContext is null")
let res = new GetBatteryInfoFailImpl(1001);
options.fail?.(res)
options.complete?.(res)
}
}
/**
* 同步获取电量
示例
* 同步获取电量
*/
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
export const getBatteryInfoSync : GetBatteryInfoSync = function () : GetBatteryInfoResult {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
...
...
@@ -65,7 +61,6 @@ export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryIn
level: level,
isCharging: isCharging
};
return res;
}
else {
...
...
@@ -78,6 +73,4 @@ export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryIn
};
return res;
}
}
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
浏览文件 @
cfdc2863
...
...
@@ -4,10 +4,9 @@ import { UIDevice } from "UIKit";
import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoResult, GetBatteryInfoSync } from '../interface.uts';
/**
*
导出 获取电量方法
*
异步获取电量
*/
export const getBatteryInfo : GetBatteryInfo = function (options) {
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
...
...
@@ -21,8 +20,10 @@ export const getBatteryInfo : GetBatteryInfo = function (options) {
options.complete?.(res);
}
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
/**
* 同步获取电量
*/
export const getBatteryInfoSync : GetBatteryInfoSync = function () : GetBatteryInfoResult {
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
...
...
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
浏览文件 @
cfdc2863
...
...
@@ -10,27 +10,6 @@ export type GetBatteryInfoSuccess = {
isCharging : boolean
}
// export type GetBatteryInfoFail = {
// /**
// * 错误码
// */
// errCode : number,
// /**
// * 调用API的名称
// */
// errSubject : string,
// /**
// * 错误的详细信息
// */
// errMsg : string,
// /**
// * 错误来源
// */
// cause : any | null
// }
export type GetBatteryInfoOptions = {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
...
...
@@ -57,6 +36,18 @@ export type GetBatteryInfoResult = {
isCharging : boolean
}
/**
* 错误码
* - 1001 getAppContext is null
*/
export type GetBatteryInfoErrorCode = 1001 ;
/**
* GetBatteryInfo 的错误回调参数
*/
export interface GetBatteryInfoFail extends IUniError {
errCode : GetBatteryInfoErrorCode
};
/**
* 获取电量信息
* @param {GetBatteryInfoOptions} options
...
...
@@ -98,10 +89,14 @@ interface Uni {
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "
9.0",
* "osVer": "
12.0",
* "uniVer": "3.6.11",
* "unixVer": "
3.9.0"
* "unixVer": "
4.11"
* }
* },
* "web": {
* "uniVer": "3.6.11",
* "unixVer": "4.0"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
...
...
@@ -125,10 +120,14 @@ interface Uni {
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "
9
.0",
* "osVer": "
12
.0",
* "uniVer": "3.6.11",
* "unixVer": "
3.9.0
"
* "unixVer": "
4.11
"
* }
* },
* "web": {
* "uniVer": "3.6.11",
* "unixVer": "4.0"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
...
...
uni_modules/uni-getbatteryinfo/utssdk/unierror.uts
0 → 100644
浏览文件 @
cfdc2863
import { GetBatteryInfoErrorCode, GetBatteryInfoFail } from "./interface.uts"
/**
* 错误主题
*/
export const UniErrorSubject = 'uni-getBatteryInfo';
/**
* 错误信息
* @UniError
*/
export const UniErrors : Map<GetBatteryInfoErrorCode, string> = new Map([
/**
* 错误码及对应的错误信息
*/
[1001, 'getBatteryInfo:fail getAppContext is null'],
]);
/**
* 错误对象实现
*/
export class GetBatteryInfoFailImpl extends UniError implements GetBatteryInfoFail {
/**
* 错误对象构造函数
*/
constructor(errCode : GetBatteryInfoErrorCode) {
super();
this.errSubject = UniErrorSubject;
this.errCode = errCode;
this.errMsg = UniErrors[errCode] ?? "";
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录