Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
2722c735
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看板
提交
2722c735
编写于
9月 15, 2023
作者:
DCloud-yyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新uni-getbatteryinfo模块到1.3.1
上级
1b3ad13e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
86 addition
and
69 deletion
+86
-69
uni_modules/uni-getbatteryinfo/changelog.md
uni_modules/uni-getbatteryinfo/changelog.md
+6
-1
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
+68
-68
uni_modules/uni-getbatteryinfo/utssdk/mp-alipay/index.js
uni_modules/uni-getbatteryinfo/utssdk/mp-alipay/index.js
+3
-0
uni_modules/uni-getbatteryinfo/utssdk/mp-baidu/index.js
uni_modules/uni-getbatteryinfo/utssdk/mp-baidu/index.js
+3
-0
uni_modules/uni-getbatteryinfo/utssdk/mp-qq/index.js
uni_modules/uni-getbatteryinfo/utssdk/mp-qq/index.js
+3
-0
uni_modules/uni-getbatteryinfo/utssdk/mp-weixin/index.js
uni_modules/uni-getbatteryinfo/utssdk/mp-weixin/index.js
+3
-0
未找到文件。
uni_modules/uni-getbatteryinfo/changelog.md
浏览文件 @
2722c735
## 1.3.1(2023-09-15)
app端适配使用UniError
## 1.3.0(2023-05-30)
+
新增 同步获取电量api
新增 同步获取电量api
## 1.2.0(2022-10-17)
实现百度小程序/支付宝小程序/QQ小程序获取电量
## 1.1.0(2022-10-17)
实现ios平台获取电量
...
...
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
浏览文件 @
2722c735
import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import { UTSAndroid } from "io.dcloud.uts";
import { GetBatteryInfo, GetBatteryInfo
Success, GetBatteryInfoFail, GetBatteryInfoResult,GetBatteryInfoSync } from '../interface.uts'
/**
* 异步获取电量
*
@param {Object} options
*/
export const getBatteryInfo : GetBatteryInfo = function (options) {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
const res : GetBatteryInfoSuccess = {
errMsg: 'getBatteryInfo:ok',
level,
isCharging: manager.isCharging()
}
options.
success?.(res)
options.complete?.(res)
} else {
const res : GetBatteryInfoFail = {
errSubject: "uni-getBatteryInfo",
errCode: 1001,
errMsg: 'getBatteryInfo:fail getAppContext is null',
cause: null
}
options.fail?.(res)
options.complete?.(res)
}
}
/**
* 同步获取电量示例
*/
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
const res : GetBatteryInfoResult = {
level: level,
isCharging: manager.isCharging()
};
return res;
} else {
/**
* 无有效上下文
*/
const res : GetBatteryInfoResult = {
level: -1,
isCharging: false
};
return res;
}
import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import { UTSAndroid } from "io.dcloud.uts";
import { GetBatteryInfo, GetBatteryInfo
Options, GetBatteryInfoSuccess, GetBatteryInfoResult,GetBatteryInfoSync } from '../interface.uts'
/**
* 异步获取电量
*
/
export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
const res : GetBatteryInfoSuccess = {
errMsg: 'getBatteryInfo:ok',
level,
isCharging: manager.isCharging()
}
options.success?.(res)
options.
complete?.(res)
} else {
// const res : GetBatteryInfoFail = {
// errSubject: "uni-getBatteryInfo",
// errCode: 1001,
// errMsg: 'getBatteryInfo:fail getAppContext is null',
// cause: null
// }
const res = new UniError("uni-getBatteryInfo", 1001, "getBatteryInfo:fail getAppContext is null")
options.fail?.(res)
options.complete?.(res)
}
}
/**
* 同步获取电量示例
*/
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
const res : GetBatteryInfoResult = {
level: level,
isCharging: manager.isCharging()
};
return res;
} else {
/**
* 无有效上下文
*/
const res : GetBatteryInfoResult = {
level: -1,
isCharging: false
};
return res;
}
}
\ No newline at end of file
uni_modules/uni-getbatteryinfo/utssdk/mp-alipay/index.js
浏览文件 @
2722c735
export
function
getBatteryInfo
(
options
)
{
return
my
.
getBatteryInfo
(
options
)
}
export
function
getBatteryInfoSync
(
options
)
{
return
my
.
getBatteryInfoSync
(
options
)
}
uni_modules/uni-getbatteryinfo/utssdk/mp-baidu/index.js
浏览文件 @
2722c735
export
function
getBatteryInfo
(
options
)
{
return
swan
.
getBatteryInfo
(
options
)
}
export
function
getBatteryInfoSync
(
options
)
{
return
swan
.
getBatteryInfoSync
(
options
)
}
uni_modules/uni-getbatteryinfo/utssdk/mp-qq/index.js
浏览文件 @
2722c735
export
function
getBatteryInfo
(
options
)
{
return
qq
.
getBatteryInfo
(
options
)
}
export
function
getBatteryInfoSync
(
options
)
{
return
qq
.
getBatteryInfoSync
(
options
)
}
uni_modules/uni-getbatteryinfo/utssdk/mp-weixin/index.js
浏览文件 @
2722c735
export
function
getBatteryInfo
(
options
)
{
return
wx
.
getBatteryInfo
(
options
)
}
export
function
getBatteryInfoSync
(
options
)
{
return
wx
.
getBatteryInfoSync
(
options
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录