nativeScript-powerinfo
by phil_adams | v1.0.7
battery and power information NativeScript 插件。
npm i --save nativescript-powerinfo

NativeScript 电池 & 功率插件

NativeScript 电池 & 功率插件

安装

tns plugin add nativescript-powerinfo

用法

JavaScript

var power = require("nativescript-powerinfo");

//Start Power Updates
power.startPowerUpdates(function(Info) {
console.log("battery charge: " + Info.percentage + "%");
});

//Stop Power Updates
stopPowerUpdates();

TypeScript

let power = require("nativescript-powerinfo");

//Start Power Updates
power.startPowerUpdates(function(Info) {
console.log("battery charge: " + Info.percentage + "%");
});

//Stop Power Updates
stopPowerUpdates();

信息结构

回调结果

  • Info.health 返回

    • 包含当前与以下相关的健康常数的整数。
    • android.os.BatteryManager.BATTERY_HEALTH_COLD
    • android.os.BatteryManager.BATTERY_HEALTH_DEAD
    • android.os.BatteryManager.BATTERY_HEALTH_GOOD
    • android.os.BatteryManager.BATTERY_HEALTH_OVERHEAT
    • android.os.BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE
    • android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN
    • android.os.BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE
  • Info.icon_small 返回

    • 包含表示当前电池状态的较小状态栏图标资源 ID 的整数。
  • Info.present 返回

    • 表示是否有电池存在的布尔值。
  • Info.plugged 返回

    • 表示设备是否连接到电源的整数;0 表示正在使用电池,其他常数为不同类型的电源。
    • android.os.BatteryManager.BATTERY_PLUGGED_AC
    • android.os.BatteryManager.BATTERY_PLUGGED_USB
    • android.os.BatteryManager.BATTERY_PLUGGED_WIRELESS
  • Info.percent 返回

    • 包含剩余电池百分比的整数。
  • Info.level 返回

    • 包含当前电池水平的整数,从 0 到 Info.scale。
  • Info.scale 返回

    • 包含最大电池水平的整数。
  • Info.status 返回

    • 包含当前状态常数的整数。
    • android.os.BatteryManager.BATTERY_STATUS_CHARGING
    • android.os.BatteryManager.BATTERY_STATUS_DISCHARGING
    • android.os.BatteryManager.BATTERY_STATUS_FULL
    • android.os.BatteryManager.BATTERY_STATUS_NOT_CHARGING
    • android.os.BatteryManager.BATTERY_STATUS_UNKNOWN
  • Info.technology 返回

    • 描述当前电池技术的字符串。
  • Info.temperature 返回

    • 包含当前电池温度的整数。
  • Info.voltage 返回

    • 包含当前电池电压水平的整数。

Android BatteryManager SDK 参考文档