Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
c95a0c0e
U
uni-api
项目概览
DCloud
/
uni-api
通知
670
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看板
提交
c95a0c0e
编写于
9月 25, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uniappx modules 修改同步到获取电量主仓库
上级
ace59dd7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
54 addition
and
38 deletion
+54
-38
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
+42
-29
uni_modules/uni-getbatteryinfo/utssdk/app-ios/config.json
uni_modules/uni-getbatteryinfo/utssdk/app-ios/config.json
+3
-0
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
+2
-2
uni_modules/uni-getbatteryinfo/utssdk/index.d.ts
uni_modules/uni-getbatteryinfo/utssdk/index.d.ts
+1
-1
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
+6
-6
未找到文件。
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
浏览文件 @
c95a0c0e
...
@@ -2,12 +2,16 @@ import Context from "android.content.Context";
...
@@ -2,12 +2,16 @@ import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
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';
/**
/**
* 异步获取电量
* 异步获取电量
*/
*/
export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) {
export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) {
const context = UTSAndroid.getAppContext();
const context = UTSAndroid.getAppContext();
if (context != null) {
if (context != null) {
const manager = context.getSystemService(
const manager = context.getSystemService(
...
@@ -15,21 +19,21 @@ export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInf
...
@@ -15,21 +19,21 @@ export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInf
) as BatteryManager;
) as BatteryManager;
const level = manager.getIntProperty(
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
);
let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
let batteryStatus = context.registerReceiver(null, ifilter);
let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
const res : GetBatteryInfoSuccess = {
const res : GetBatteryInfoSuccess = {
errMsg: 'getBatteryInfo:ok',
errMsg: 'getBatteryInfo:ok',
level,
level,
isCharging:
manager.isCharging()
isCharging:
isCharging
}
}
options.success?.(res)
options.success?.(res)
options.complete?.(res)
options.complete?.(res)
} else {
} 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")
const res = new UniError("uni-getBatteryInfo", 1001, "getBatteryInfo:fail getAppContext is null")
options.fail?.(res)
options.fail?.(res)
options.complete?.(res)
options.complete?.(res)
...
@@ -40,31 +44,40 @@ export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInf
...
@@ -40,31 +44,40 @@ export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInf
* 同步获取电量示例
* 同步获取电量示例
*/
*/
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
const context = UTSAndroid.getAppContext();
const context = UTSAndroid.getAppContext();
if (context != null) {
if (context != null) {
const manager = context.getSystemService(
const manager = context.getSystemService(
Context.BATTERY_SERVICE
Context.BATTERY_SERVICE
) as BatteryManager;
) as BatteryManager;
const level = manager.getIntProperty(
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
);
const res : GetBatteryInfoResult = {
let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
level: level,
let batteryStatus = context.registerReceiver(null, ifilter);
isCharging: manager.isCharging()
let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
};
let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
return res;
} else {
const res : GetBatteryInfoResult = {
/**
level: level,
* 无有效上下文
isCharging: isCharging
*/
};
const res : GetBatteryInfoResult = {
level: -1,
return res;
isCharging: false
}
};
else {
return res;
/**
* 无有效上下文
*/
const res : GetBatteryInfoResult = {
level: -1,
isCharging: false
};
return res;
}
}
}
}
\ No newline at end of file
uni_modules/uni-getbatteryinfo/utssdk/app-ios/config.json
0 → 100644
浏览文件 @
c95a0c0e
{
"deploymentTarget"
:
"9"
}
\ No newline at end of file
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
浏览文件 @
c95a0c0e
...
@@ -20,8 +20,8 @@ export const getBatteryInfo : GetBatteryInfo = function (options) {
...
@@ -20,8 +20,8 @@ export const getBatteryInfo : GetBatteryInfo = function (options) {
};
};
options.success?.(res);
options.success?.(res);
options.complete?.(res);
options.complete?.(res);
}
}
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
// 开启电量检测
// 开启电量检测
...
...
uni_modules/uni-getbatteryinfo/utssdk/index.d.ts
浏览文件 @
c95a0c0e
...
@@ -38,5 +38,5 @@ declare interface Uni {
...
@@ -38,5 +38,5 @@ declare interface Uni {
/**
/**
* 同步获取电池电量信息
* 同步获取电池电量信息
*/
*/
G
etBatteryInfoSync
():
UniNamespace
.
GetBatteryInfoSuccessCallbackResult
;
g
etBatteryInfoSync
():
UniNamespace
.
GetBatteryInfoSuccessCallbackResult
;
}
}
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
浏览文件 @
c95a0c0e
...
@@ -60,12 +60,12 @@ export type GetBatteryInfoResult = {
...
@@ -60,12 +60,12 @@ export type GetBatteryInfoResult = {
/**
/**
* 获取电量信息
* 获取电量信息
* @param {GetBatteryInfoOptions} options
* @param {GetBatteryInfoOptions} options
*
*
*
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.11
* @since 3.6.11
*
*
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
*/
...
@@ -79,7 +79,7 @@ interface Uni {
...
@@ -79,7 +79,7 @@ interface Uni {
/**
/**
* 获取电池电量信息
* 获取电池电量信息
* @description 获取电池电量信息
* @description 获取电池电量信息
* @param {GetBatteryInfoOptions} options
* @param {GetBatteryInfoOptions} options
* @example
* @example
* ```typescript
* ```typescript
* uni.getBatteryInfo({
* uni.getBatteryInfo({
...
@@ -107,7 +107,7 @@ interface Uni {
...
@@ -107,7 +107,7 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @uniVueVersion 2,3 //支持的vue版本
*
*
*/
*/
getBatteryInfo(options : GetBatteryInfoOptions) : void,
getBatteryInfo
(options : GetBatteryInfoOptions) : void,
/**
/**
* 同步获取电池电量信息
* 同步获取电池电量信息
* @description 获取电池电量信息
* @description 获取电池电量信息
...
@@ -134,6 +134,6 @@ interface Uni {
...
@@ -134,6 +134,6 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @uniVueVersion 2,3 //支持的vue版本
*
*
*/
*/
getBatteryInfoSync()
:
GetBatteryInfoResult
getBatteryInfoSync()
:
GetBatteryInfoResult
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录