我在Cordova中有以下代码
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-inline' 'self' http://192.168.1.102/app.php data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="../css/index.css">
<script type="text/javascript" src="../cordova.js"></script>
<script type="text/javascript" src="../js/index.js"></script>
<title>ÍNDICE DE API'S</title>
<script>
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
window.addEventListener("batterystatus", onBatteryStatus, false);
}
function onBatteryStatus(status) {
alert("Level: " + status.level + " isPlugged: " + status.isPlugged);
}
</script>
</head>
<body onload="onLoad()">
</body>
但电池插件不起作用。我尝试了几次不同的方式,但没有工作......
任何人都可以帮助我?
注意:
该文件位于子文件夹
中谢谢!
编辑:
[ROOT FOLDER]
-www
--css
--js
--img
--js
--folder
- -battery.html
我的config.xml
答案 0 :(得分:0)
您可以使用命令read more here
安装cordova电池插件 cordova plugin add cordova-plugin-battery-status
试试这段代码......
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
</div>
<button onClick="ShowBatteryStatus()">Show Battery Status</button>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script>
function ShowBatteryStatus() {
window.addEventListener("batterystatus", onBatteryStatus, false);
}
function onBatteryStatus(status) {
alert("Level: " + status.level + " isPlugged: " + status.isPlugged);
}
</script>
</body>
</html>