如何动态获取设备信息
获取设备信息插件:1.基本设备信息 cordova plugin add cordova-plugin-device 2.电池状态信息 cordova plugin add cordova-plugin-battery-status
一、html文件代码
<div class="bg">
<p id="information"> </p>
</div>
二、js文件代码
function info(){
console.log("info.ok...");
window.addEventListener("batterystatus",onBatteryInfo,false);
function onBatteryInfo(info){
console.log("onBatteryInfo.ok...");
var s="<center>"+'设备信息'+"</center><br/>";
s+='设备名称:'+device.name+"<br/>";
s+='设备编号:'+device.model+"<br/>";
s+='操作系统:'+device.platform+"<br/>";
s+='操作系统版本:'+device.version+"<br/>";
s+='当前电量:'+info.level+'%'+"<br/>";
s+='是否在充电:'+info.isPlugged;
$("#information").html(s);
}
}