Battery time calculation
I am wondering if there is any library for calculating remaining battery time on mobile devices like the iPhone, iPad, android phones etc? Or if there is any hope of doing any reasonable assumptions about battery usage depending on properties like:
- Screen brightness
- Radio usage (network, WIFI/3G/4G/bluetooth)
- User interaction level
- CPU utilization
I am thinking that it might be possible to find out how these properties affect the battery life and in that way be able to develop some kind of library to be able to warn users about low battery levels when you know for how long the user will need to use the device. You could then:
- Ask the user to lower the screen brightness
- Ask the user to turn off WIFI/3G (or switch)
- Automatically lower the update polling frequency of any network operations
I have a limited knowledge of physics and electronics, but it seems to me that it should be possible to do this? Ive googled and not 开发者_如何学Gofound anything like this.
This feature is really hard to develop because it depends on many factors. You better implement the native battery notifications for every specific platform. Some platforms deliver quite comprehensive information about power consumption and remaining battery life. This will (probably) result in better estimates 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];
Every 5% battery decrease triggers the UIDeviceBatteryLevelDidChangeNotification. If you know how long the device worked on 5% battery charge, you can estimate how long it will be working on the residual battery charge. In my experience this method results in quite reliable estimates.
In this case: When your applications detects quick battery drainage, you check which power consuming features are enabled and advice to user to disable the enabled ones (WiFi, high brightness, etc).
Besides, applications that constantly check for many system variables do consume quite some power. This makes your application 'unprofitable' in terms of saving power.
精彩评论