D:\worksp\cordova\CordovaProject>cordova plugin add cordova-plugin-battery-status
window.addEventListener("batterystatus", onBatteryStatus, false);
function onBatteryStatus(info) {
alert("BATTERY STATUS: Level: " + info.level + " isPlugged: " + info.isPlugged);
}


這個插件除了提供電池狀態(tài)還有另外兩個事件。 這些事件可以以同樣的方式作為電池狀態(tài)事件被使用。
| 事件 | 詳細 |
|---|---|
| batterylow |
當電池電量百分比達到了較低的值時,則觸發(fā)此事件。此值在不同的設備可能有所不同。
|
| batterycritical |
當電池電量百分比達到臨界值時,則觸發(fā)此事件。此值在不同的設備可能有所不同。
|