This question is locked. New answers and comments are not allowed.
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?
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?
9 Answers, 1 is accepted
0
Leonardo
Top achievements
Rank 1
answered on 12 May 2014, 11:02 PM
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.
0
Isaac
Top achievements
Rank 1
answered on 26 May 2014, 07:19 PM
I'm having that same problem.
How did you make it work? Where did you add the batterystatus event listener?
Thanks
How did you make it work? Where did you add the batterystatus event listener?
Thanks
0
Leonardo
Top achievements
Rank 1
answered on 26 May 2014, 07:27 PM
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.
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.
0
Isaac
Top achievements
Rank 1
answered on 26 May 2014, 07:51 PM
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?
I'm doing that, but still, no batterystatus events fire. What version of Android are you using?
ps: are you brazilian?
0
Leonardo
Top achievements
Rank 1
answered on 26 May 2014, 08:20 PM
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
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
0
Isaac
Top achievements
Rank 1
answered on 26 May 2014, 08:39 PM
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 :)
<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 :)
0
Leonardo
Top achievements
Rank 1
answered on 26 May 2014, 08:47 PM
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?
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?
0
Isaac
Top achievements
Rank 1
answered on 26 May 2014, 09:55 PM
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.
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.
0
Leonardo
Top achievements
Rank 1
answered on 26 May 2014, 10:10 PM
Great. You are welcome.
PS: hahaha
PS: hahaha