Core plugins not working

10 posts, 0 answers
  1. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 12 May 2014 Link to this post

    Hey,

    I am having some troubles trying to use a couple of core plugins. I have read the documentation in which I learnt that I only have to tick which plugin I need in the properties file. I don't have to add anything to the xml files... But, it still doesn't work.

    I would like to get the battery level using the Battery status callback and to make the phone vibrate.

    I have tick that and added these lines to my index.html file but it is not working;


    <script type="text/javascript">
            navigator.notification.vibrate(2500);
        window.addEventListener("batterystatus", batteryStatusCallback, false);
            
        function batteryStatusCallback(info)
    {
            alert("Level: " + info.level + " isPlugged: " + info.isPlugged);
    }
    </script> 


    Do you have any idea what I am missing? 

  2. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 12 May 2014 in reply to Leonardo Link to this post

    It is working now. I had to add the event in another part of my code. I would like to delete this post if it were possible.
  3. Isaac
    Isaac avatar
    4 posts
    Member since:
    May 2014

    Posted 26 May 2014 in reply to Leonardo Link to this post

    I'm having that same problem.

    How did you make it work? Where did you add the batterystatus event listener? 

    Thanks
  4. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 26 May 2014 in reply to Leonardo Link to this post

    Hey Isaac,

    I added this line after the deviceready event is called:

    window.addEventListener("batterystatus", function (info) {alert("Level: " + info.level + " isPlugged: " + info.isPlugged);
    }, false);

    This actually works and the alert is shown.

    My error was that I didn't wait for the device to be ready to add PhoneGap plugins. That's why deviceready event exists, I guess.

    Hope that helps you.

  5. Isaac
    Isaac avatar
    4 posts
    Member since:
    May 2014

    Posted 26 May 2014 in reply to Leonardo Link to this post

    Thanks Leonardo for the quick response.

    I'm doing that, but still, no batterystatus events fire. What version of Android are you using?

    ps: are you brazilian?
  6. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 26 May 2014 in reply to Isaac Link to this post

    I am running on Android 4.1.2. I had to add this line to the Android Manifest file: <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="16" />

    Do you know how to access to it? What version of Android are you using?

    PS: I am Uruguayan and we are going to win the World Cup... : ) haha
  7. Isaac
    Isaac avatar
    4 posts
    Member since:
    May 2014

    Posted 26 May 2014 in reply to Leonardo Link to this post

    Mine was set to: 
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />

    Even though it probably wouldn't help, I've set mine to 14 and 16 like just to make sure. Still doesn't work :/

    I'll start a blank Cordova project and then try just that, don't know what else to do.

    PS: I would actually like to see Uruguay win the World Cup over Brazil :)

      
  8. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 26 May 2014 in reply to Isaac Link to this post

    Maybe that's too old to work with this plugin. I don't know. I would recommend you to use Genymotion (http://www.genymotion.com/). You can test your app in a 4.4.2 device for free. Never trust in the Telerik emulator (I hope not to get kicked out due to this)

    I guess the Android version can be the reason... You have to match your real device API level to the one that you set in Manifest file (http://en.wikipedia.org/wiki/Android_version_history)

    PS: Why is that? 
  9. Isaac
    Isaac avatar
    4 posts
    Member since:
    May 2014

    Posted 26 May 2014 in reply to Leonardo Link to this post

    Hey, I created a blank Cordova project, and it's working! There's something in my app that's conflicting with the battery-status functionality. When I find out I'll post here.

    I've been using Jsconsole. It has some weird issues (see my post here: http://stackoverflow.com/questions/23785888/jsconsole-showing-console-messages-in-weird-order-when-debugging-cordova-app-in), but it's good to be able to test the thing on a real device. But I'll try Genymotion, it looks good - thanks for the tip.

    PS: well I'm not the "typical nationalist" and I don't care much about soccer - i like to play eventually, that's all. in the end, the whole soccer industry is rather harmful for the brazilian people for various reasons. Plus , I sympathize a lot with Mujica, and also the recent  marijuana legalization.
     
  10. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 26 May 2014 in reply to Isaac Link to this post

    Great. You are welcome.

    PS: hahaha
Back to Top