Calculation of battery life

I am wondering if there is any library for calculating the remaining battery life on mobile devices such as iPhone, iPad, Android phones, etc.? Or, if there is any hope of making any reasonable assumptions about battery usage, depending on properties such as:

  • Screen brightness
  • Using radio (network, WIFI / 3G / 4G / bluetooth)
  • User interaction level
  • CPU usage

I think it would be possible to find out how these properties affect the battery life, and thus be able to create some kind of library in order to be able to warn users about a low battery level when you know how long the user will need use the device. Then you can:

  • Ask the user to lower the screen brightness.
  • Ask user to turn off WIFI / 3G (or switch)
  • Automatically reduce the frequency of polling updates for any network operations.

I have limited knowledge of physics and electronics, but it seems to me that this can be done? Ive googled and did not find anything like it.

+3
source share
1 answer

This function is very difficult to develop because it depends on many factors. You better implement your own battery notifications for each particular platform. On some platforms, there is fairly complete information about power consumption and remaining battery life. This (probably) will lead to better grades and save you a lot of work :)

Example for iPhone;

UIDevice *device = [UIDevice currentDevice];
device.batteryMonitoringEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryChanged:) name:@"UIDeviceBatteryLevelDidChangeNotification" object:device];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryChanged:) name:@"UIDeviceBatteryStateDidChangeNotification" object:device];

5% - UIDeviceBatteryLevelDidChangeNotification. , 5% , , . .

: , , , (WiFi, ..).

, , , . "" .

+4

Source: https://habr.com/ru/post/1794537/


All Articles