'energy flow in when charging a mobile or Tablet
I would like to know whether it is possible to measure how much energy is flowing in a mobile device (IOS or Android) when it is charging ? In watt per Hour or MilliAmperes per Hour for exemple.
Basically I would like to measure how much electricity I have taken from my charge. Is there a native or low level API for that ?
thanks for yout help
Solution 1:[1]
Android
Battery level checking Android
Battery level checking Android 1
See demo : Battery Demo Android
iOS
Yes in iOS Device when you charging device you can get Inforation about battery status. Notification of your batteryLevelChanged and batteryStateChanged
See demo : Batterry Demo iOS
Note : Run This demo in iOS Device. Not Simulator.
// Register for battery level and state change notifications.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(batteryLevelChanged:)
name:UIDeviceBatteryLevelDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(batteryStateChanged:)
name:UIDeviceBatteryStateDidChangeNotification object:nil];
Code for updateBatteryLevel:
- (void)updateBatteryLevel
{
float batteryLevel = [UIDevice currentDevice].batteryLevel;
if (batteryLevel < 0.0) {
// -1.0 means battery state is UIDeviceBatteryStateUnknown
self.levelLabel.text = NSLocalizedString(@"Unknown", @"");
}
else {
static NSNumberFormatter *numberFormatter = nil;
if (numberFormatter == nil) {
numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterPercentStyle];
[numberFormatter setMaximumFractionDigits:1];
}
NSNumber *levelObj = [NSNumber numberWithFloat:batteryLevel];
self.levelLabel.text = [numberFormatter stringFromNumber:levelObj];
}
}
- (void)updateBatteryState
{
NSArray *batteryStateCells = @[self.unknownCell, self.unpluggedCell, self.chargingCell, self.fullCell];
UIDeviceBatteryState currentState = [UIDevice currentDevice].batteryState;
for (int i = 0; i < [batteryStateCells count]; i++) {
UITableViewCell *cell = (UITableViewCell *) batteryStateCells[i];
if (i + UIDeviceBatteryStateUnknown == currentState) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
}
Solution 2:[2]
One of he simplest solutions (and most accurate) is to get a current meter that records the current through your wall plug. Any power measure API depends upon what instrumentation there is on the board. Sometimes it is a direct measure (accurate) and sometimes it is computed / inferred (maybe accurate, maybe very inaccurate).
These data recorders can range from industrial (more expensive, less work) to DIY (cheap, more work). Which you want depends upon how much time you have and how often you are going to use it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Taylor Kidd |
