Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
Contributor
Posts: 24
Registered: ‎01-26-2013
My Device: none
My Carrier: none
Accepted Solution

BB10: Get battery level

Hi @all,

 

I would like to know if it is possible to get the current battery level of the device.

 

I know that there is a batterystatus event (blackberry.system.batterystatus), but using this event my app has to wait until the battery level changes to receive a value.

 

My problem is that I need to get the battery level when my app has been started, not only a few minutes later when the battery level has changed.

 

Many thanks in advance!

Peter

Contributor
Posts: 24
Registered: ‎01-26-2013
My Device: none
My Carrier: none

Re: BB10: Get battery level

Ok I found a solution myself. Just use

 

var battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;

alert(battery.level);

 

 

New Developer
Posts: 10
Registered: ‎05-18-2013
My Device: Developer - no device yet
My Carrier: Developer

Re: BB10: Get battery level

For my 2 cents, you can also register to battery events through System API: 

https://developer.blackberry.com/html5/apis/blackberry.system.html#.event:batterystatus