我想查看我的应用中特定网络通话消耗了多少电池,实际上是否可以这样做。如果是的话,该怎么做?
答案 0 :(得分:0)
您可以通过以下方法获取电池信息:
public float getBatteryLevel() {
Intent batteryIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
// Error checking that probably isn't needed but I added just in case.
if(level == -1 || scale == -1) {
return 50.0f;
}
return ((float)level / (float)scale) * 100.0f; }
因此,您可以在网络呼叫之前和之后调用此方法。并找到差异。