我正在为Cordova未能检测到任何插件而苦苦挣扎。
这是我要执行的确切步骤:
~/Desktop → cordova -v
3.5.0-0.2.4
~/Desktop → cordova create test com.example.test JustATest
Creating a new cordova project with name "JustATest" and id "com.example.test" at location "/Users/adam/Desktop/test"
~/Desktop → cd test
~/Desktop/test → cordova platform add android
Creating android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.example.test
Name: JustATest
Android target: android-19
Copying template files...
Running: android update project --subprojects --path "platforms/android" --target android-19 --library "CordovaLib"
Resolved location of library project to: /Users/adam/Desktop/test/platforms/android/CordovaLib
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'JustATest'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/build.xml
Added file platforms/android/proguard-project.txt
Updated project.properties
Updated local.properties
No project name specified, using project folder name 'CordovaLib'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/CordovaLib/build.xml
Added file platforms/android/CordovaLib/proguard-project.txt
Project successfully created.
~/Desktop/test → cordova platforms ls
Installed platforms: android 3.5.0
Available platforms: amazon-fireos, blackberry10, firefoxos, ios
~/Desktop/test → cordova plugin add org.apache.cordova.battery-status
Fetching plugin "org.apache.cordova.battery-status" via plugin registry
Installing "org.apache.cordova.battery-status" for android
~/Desktop/test → cordova plugin ls
org.apache.cordova.battery-status 0.2.8 "Battery"
~/Desktop/test →
然后我打开`〜/ Desktop / test / www / index.html并更改它:
<script type="text/javascript">
app.initialize();
</script>
对此:
<script type="text/javascript">
app.initialize();
console.log("Here!");
window.addEventListener("batterystatus", onBatteryStatus, false);
function onBatteryStatus(info) {
console.log("Level: " + info.level + " isPlugged: " + info.isPlugged);
}
</script>
然后我执行以下命令:
~/Desktop/test → cordova run android
然后,我看到该应用程序在手机上启动,当我前往chrome:// inspect /时,我也看到了它,但是看不到击球手状态。这是我在浏览器控制台中获得的所有信息:
The key "target-densitydpi" is not supported. index.html:25
Here! index.html:43
Received Event: deviceready index.js:47
正如您看到的“这里!” 显示,但不显示电池状态。即使当我等待手机电池电量百分比更改时。
我想念的是什么?
如上所述,我只是创建了一个精确的构建,并且进行了一些小的更改,使之起作用:
你需要搬家
window.addEventListener('batterystatus', onBatteryStatus, false);
到app.onDeviceReady
。这是因为在加载设备API之后需要添加窗口侦听器。
我发现这隐藏在文档中:
Applications typically should use window.addEventListener to attach an event listener once the deviceready event fires.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句