我正在尝试收集 Android G1 手机的电量使用统计数据。我有兴趣了解电压和电流的值,然后能够收集本报告中报告的统计数据PDF.
我可以通过注册意向接收器来接收 ACTION_BATTERY_CHANGED 的广播来获取电池电压的值。但问题是Android并没有通过这个SDK接口公开电流的值。
我尝试的一种方法是通过 sysfs 界面,我可以使用以下命令从 adb shell 查看电池电流值
$cat /sys/class/power_supply/battery/batt_current
449
但这也仅适用于通过 USB 接口连接手机的情况。如果我断开电话,我会看到 batt_current 的值为“0”。我不确定为什么报告的电流值为零。它应该大于零,对吧?
对于获取电池电流值有什么建议/指示吗?如果我错了,还请纠正我。
您只需查看当前小部件的源代码即可。它具有某些平台存储当前值的硬编码路径。
/*
* 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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)