问题
I'm creating an application, and I need to be able to get the battery current (mA/mAh). I have the voltage/temp/level etc and this is the final thing I need to get, and coincidentally the hardest too.
I've looked at CurrentWidget source code (https://play.google.com/store/apps/details?id=com.manor.currentwidget&hl=en) and searched Google high and low, and I have all the classes/methods to pull the data out, it's just the path to the file containing the current which is stopping me from getting it.
"CurrentWidget" contains a lot of different paths to the file (for various devices) but none of them work on my ASUS EEPad Transformer on 4.0.3, which I need it to be working one as it's my testing device and all's I can get my hands on. I've been in to the adb shell and dug around the root of the tablet for hours but I can't seem to find anything apart from things like name, temp, voltage_now and others which I already have. They're all stored in /sys/class/power_supply/battery, but there's no "current" like I expected, and like there seems to be on other devices.
Thanks for any help, I know this is a long one!
回答1:
current capacity of battery can be achieved by using android developer,s function via reflection
private Object mPowerProfile_;
private static final String POWER_PROFILE_CLASS ="com.android.internal.os.PowerProfile";
mPowerProfile_ = Class.forName(POWER_PROFILE_CLASS).getConstructor(Context.class).newInstance(this);
double batteryCapacity=(Double)Class.forName(POWER_PROFILE_CLASS).getMethod("getAveragePower", java.lang.String.class).invoke(mPowerProfile_, "battery.capacity");
i think this will help
回答2:
This seems to be a repeat of Getting the battery current values for the Android Phone
But, if you were so inclined, it seems that if the current widget couldn't find the amperage for your tablet, then the tablet may not have supported writing out to that file. Either because it didn't have the specific capabilities supported in the kernel, or due to the specific hardware platform not having the requisite hardware to essentially measure current at the battery terminal itself.
As stated in the other post, most other widgets calculate percentages for the battery based on other factors besides current.
来源:https://stackoverflow.com/questions/13480341/finding-battery-current-ma-mah-on-android-tablet