Cordova not detecting official plugins

Adam Silver

I am struggling with Cordova not detecting any plugin.

Here are the exact steps I am following:

~/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 → 

Then I am opening `~/Desktop/test/www/index.html and changing this:

    <script type="text/javascript">
        app.initialize();       
    </script>

To this:

    <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>

Then I am executing this command:

~/Desktop/test → cordova run android

Then I am seeing the application launching on my phone and when I head to chrome://inspect/ I see it too but I don't see the batter status. Here's all I am getting in my browser console:

The key "target-densitydpi" is not supported. index.html:25
Here! index.html:43
Received Event: deviceready index.js:47

As you see "Here!" is displayed but not the battery status. Even when I wait for the phone battery percentage to change.

What I am missing?

Dawson Loudon

I just create an exact build as you described above and I was able to make a small change that worked:

You need to move

window.addEventListener('batterystatus', onBatteryStatus, false);

to app.onDeviceReady. This is because the window listener needs to be added after the device APIs have been loaded.

I found this hidden in the documentation:

Applications typically should use window.addEventListener to attach an event listener once the deviceready event fires.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related