簡體   English   中英

Cordova 未檢測到官方插件

[英]Cordova not detecting official plugins

我正在努力解決 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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM