Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
2e102333
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2e102333
编写于
10月 14, 2022
作者:
DCloud_iOS_XHY
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of gitcode.net:dcloud/hello-uts into dev
上级
a53f1b66
d8d6fd34
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
13 addition
and
29 deletion
+13
-29
pages/SystemAPI/SystemAPI.vue
pages/SystemAPI/SystemAPI.vue
+1
-2
uni_modules/uni-getbatteryinfo/package.json
uni_modules/uni-getbatteryinfo/package.json
+4
-1
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
+6
-20
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
+2
-6
未找到文件。
pages/SystemAPI/SystemAPI.vue
浏览文件 @
2e102333
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
</view>
</view>
</
template
>
</
template
>
<
script
>
<
script
>
import
getBatteryInfo
from
"
@/uni_modules/uni-getbatteryinfo
"
;
import
gotoDemoActivity
from
"
@/uni_modules/uts-nativepage
"
;
import
gotoDemoActivity
from
"
@/uni_modules/uts-nativepage
"
;
...
@@ -36,7 +35,7 @@
...
@@ -36,7 +35,7 @@
onUnload
:
function
()
{},
onUnload
:
function
()
{},
methods
:
{
methods
:
{
testGetBatteryCapacity
()
{
testGetBatteryCapacity
()
{
getBatteryInfo
({
uni
.
getBatteryInfo
({
success
(
res
)
{
success
(
res
)
{
uni
.
showToast
({
uni
.
showToast
({
title
:
"
当前电量:
"
+
res
.
level
+
'
%
'
,
title
:
"
当前电量:
"
+
res
.
level
+
'
%
'
,
...
...
uni_modules/uni-getbatteryinfo/package.json
浏览文件 @
2e102333
...
@@ -30,7 +30,10 @@
...
@@ -30,7 +30,10 @@
},
},
"npmurl"
:
""
"npmurl"
:
""
},
},
"uni_modules"
:
{
"uni_modules"
:
{
"exports"
:
{
"uni"
:
"getBatteryInfo"
},
"dependencies"
:
[],
"dependencies"
:
[],
"encrypt"
:
[],
"encrypt"
:
[],
"platforms"
:
{
"platforms"
:
{
...
...
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
浏览文件 @
2e102333
...
@@ -9,41 +9,27 @@ type GetBatteryInfoOptions = {
...
@@ -9,41 +9,27 @@ type GetBatteryInfoOptions = {
complete?: (res: UTSJSONObject) => void
complete?: (res: UTSJSONObject) => void
}
}
export
default
async
function
getBatteryInfo
(
options
:
GetBatteryInfoOptions
)
{
export default function getBatteryInfo(options: GetBatteryInfoOptions) {
const context = getAppContext();
const context = getAppContext();
console
.
log
(
context
);
if (context != null) {
if (context != null) {
const manager = context.getSystemService(
const manager = context.getSystemService(
Context.BATTERY_SERVICE
Context.BATTERY_SERVICE
) as BatteryManager;
) as BatteryManager;
console
.
log
(
manager
);
const level = manager.getIntProperty(
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
);
const res = {
const res = {
errMsg: 'getBatteryInfo:ok',
errMsg: 'getBatteryInfo:ok',
level,
level,
isCharging: manager.isCharging()
isCharging: manager.isCharging()
}
}
console
.
log
(
res
);
options.success?.(res)
if
(
options
.
success
!=
null
)
{
options.complete?.(res)
options
.
success
!
(
res
)
}
console
.
log
(
"options.success"
);
if
(
options
.
complete
!=
null
)
{
options
.
complete
!
(
res
)
}
console
.
log
(
"options.complete"
);
} else {
} else {
const res = {
const res = {
errMsg: 'getBatteryInfo:fail getAppContext is null'
errMsg: 'getBatteryInfo:fail getAppContext is null'
}
}
if
(
options
.
fail
!=
null
)
{
options.fail?.(res)
options
.
fail
!
(
res
)
options.complete?.(res)
}
if
(
options
.
complete
!=
null
)
{
options
.
complete
!
(
res
)
}
}
}
}
}
\ No newline at end of file
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
浏览文件 @
2e102333
...
@@ -15,10 +15,6 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
...
@@ -15,10 +15,6 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
level: Number(UIDevice.current.batteryLevel * 100),
level: Number(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
};
};
if (options.success != null) {
options.success?.(res);
options.success!(res);
options.complete?.(res);
}
if (options.complete != null) {
options.complete!(res);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录