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

Native Development

Reply
Developer
Posts: 125
Registered: ‎11-06-2012
My Device: BlackBerry
My Carrier: Mobifone

Re: Some help with battery info

Yes, the same result. I don't even know the return value is in minute, second or milisecond :smileysad:. And one more information, these two block of code return 2 diffirent value

 

    [ battery_info_t *info;
    return battery_info_get_time_to_full(info); ]

    [ battery_info_t *pointer = NULL;
    battery_get_info(&pointer);
    int t = battery_info_get_time_to_full(pointer); ]

Developer
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
My Carrier: Vodafone

Re: Some help with battery info

oh:smileysad: I need to get this working properly. Hope somebody will answer 

Rujuta Trivedi
Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Some help with battery info

[ Edited ]

The first snippet is incorrect, the second one should work (but it's better to process the errors properly).

Are you running it on a simulator or on a device? According to the docs it should return time in minutes.

 

battery_info_t *info = NULL;
if (BPS_SUCCESS == battery_get_info(&info))
{
  int timeToFull = battery_info_get_time_to_full(info);
  if (timeToFull == BATTERY_TIME_NA)
  {
    qDebug() << "Battery is not being charged right now\n";
  }
  else if (timeToFull == BPS_FAILURE)
  {
    qDebug() << "Failure obtaining time to charge\n";
  }
  else
  {
    qDebug() << "Time to charge is" << timeToFull << " minutes.\n";
  }

  battery_free_info(&info);
}
else
{
  qDebug() << "Unable to get battery info\n";
}

 Could you post which value are you getting using the code above?

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 125
Registered: ‎11-06-2012
My Device: BlackBerry
My Carrier: Mobifone

Re: Some help with battery info

I think the first snippet is wrong too, but it's still return value. The value of time to empty is 65535, I dont think it in minute.

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Some help with battery info

The first snippet returns a random garbage memory value because the function is called on an unitialized variable.

 

65535 is a special return value, quoting the docs:

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_re...

 

BATTERY_TIME_NA = 65535

 

A special value returned by the battery_info_get_time_to_empty() and battery_info_get_time_to_full() functions to indicate that their value is not applicable.

 

For example, when the device is plugged in, the battery does not discharge, therefore a call to the battery_info_get_time_to_empty() function will return BATTERY_TIME_NA. Similarly, when the device is not plugged in, the battery does not charge, therefore, a call to the battery_info_get_time_to_full() function will return BATTERY_TIME_NA.

 

Is the device plugged into the charger? It may not work on a simulator.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 125
Registered: ‎11-06-2012
My Device: BlackBerry
My Carrier: Mobifone

Re: Some help with battery info

I'll check it again and post the result soon, thanks Zmey.

Developer
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
My Carrier: Vodafone

Re: Some help with battery info

Hi Zmey, 

I have used ur code and checked in my application. it sometimes give me proper value in minutes but sometimes give msg "Battery is not being charged right now" while i can see the battery is being charged

Rujuta Trivedi