提交 2722c735 编写于 作者: DCloud-yyl's avatar DCloud-yyl

更新uni-getbatteryinfo模块到1.3.1

上级 1b3ad13e
## 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平台获取电量
......
import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import { UTSAndroid } from "io.dcloud.uts";
import { GetBatteryInfo, GetBatteryInfoSuccess, 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, GetBatteryInfoOptions, 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
export function getBatteryInfo(options) {
return my.getBatteryInfo(options)
}
export function getBatteryInfoSync(options) {
return my.getBatteryInfoSync(options)
}
export function getBatteryInfo(options) {
return swan.getBatteryInfo(options)
}
export function getBatteryInfoSync(options) {
return swan.getBatteryInfoSync(options)
}
export function getBatteryInfo(options) {
return qq.getBatteryInfo(options)
}
export function getBatteryInfoSync(options) {
return qq.getBatteryInfoSync(options)
}
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.
先完成此消息的编辑!
想要评论请 注册