I'd like to write an app to read stats about the incoming power supply while charging the device (e.g. voltage, milliamps etc). This info could have several uses, such as comparing the capabilities of charging via different means: - AC socket with 1m cord vs 3m cord - Car charger - PC USB vs Laptop USB - Etc....
I've tried to find this using Dr Google, but all I was able to find was the ability to read battery stats (e.g. current percentage, charging/unplugged state), not input stats.
Thanks.
After several experiments and help from various other groups, I found out that there is no way of getting Battery Current value through software only (as its not supported in h/w). Only way I found was to measure current flowing through battery by means of multimeter.
You can try with the below given example and check ...
You could just look at the source code for the Current Widget. It has hard coded path's to where certain platforms store the current values.
/*
* Copyright (c) 2010-2011 Ran Manor
*
* This file is part of CurrentWidget.
*
* CurrentWidget is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CurrentWidget is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CurrentWidget. If not, see <http://www.gnu.org/licenses/>.
*/
package com.manor.currentwidget.library;
import java.io.File;
import android.os.Build;
import android.util.Log;
public class CurrentReaderFactory {
static public Long getValue() {
File f = null;
// htc desire hd / desire z / inspire?
if (Build.MODEL.toLowerCase().contains("desire hd") ||
Build.MODEL.toLowerCase().contains("desire z") ||
Build.MODEL.toLowerCase().contains("inspire")) {
f = new File("/sys/class/power_supply/battery/batt_current");
if (f.exists()) {
return OneLineReader.getValue(f, false);
}
}
// nexus one cyangoenmod
f = new File("/sys/devices/platform/ds2784-battery/getcurrent");
if (f.exists()) {
return OneLineReader.getValue(f, true);
}
// sony ericsson xperia x1
f = new File("/sys/devices/platform/i2c-adapter/i2c-0/0-0036/power_supply/ds2746-battery/current_now");
if (f.exists()) {
return OneLineReader.getValue(f, false);
}
// xdandroid
/*if (Build.MODEL.equalsIgnoreCase("MSM")) {*/
f = new File("/sys/devices/platform/i2c-adapter/i2c-0/0-0036/power_supply/battery/current_now");
if (f.exists()) {
return OneLineReader.getValue(f, false);
}
/*}*/
// droid eris
f = new File("/sys/class/power_supply/battery/smem_text");
if (f.exists()) {
Long value = SMemTextReader.getValue();
if (value != null)
return value;
}
// htc sensation / evo 3d
f = new File("/sys/class/power_supply/battery/batt_attr_text");
if (f.exists())
{
Long value = BattAttrTextReader.getValue();
if (value != null)
return value;
}
// some htc devices
f = new File("/sys/class/power_supply/battery/batt_current");
if (f.exists())
return OneLineReader.getValue(f, false);
// nexus one
f = new File("/sys/class/power_supply/battery/current_now");
if (f.exists())
return OneLineReader.getValue(f, true);
// samsung galaxy vibrant
f = new File("/sys/class/power_supply/battery/batt_chg_current");
if (f.exists())
return OneLineReader.getValue(f, false);
// sony ericsson x10
f = new File("/sys/class/power_supply/battery/charger_current");
if (f.exists())
return OneLineReader.getValue(f, false);
// Nook Color
f = new File("/sys/class/power_supply/max17042-0/current_now");
if (f.exists())
return OneLineReader.getValue(f, false);
return null;
}
}