我有一个简单的广播器来监听 ON_CHANGE 事件,所以我的主要问题是为什么我的手机有时不是下降 1%,而是下降 2%、3% 或 4%?
有时感觉手机睡着了,没有收到那个意图,但一段时间后它从睡眠中恢复过来,不是 1%,而是 4% 编辑
/* Broadcast Receiver for battery stats */
IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
batteryLevelReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent){
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
int isCharging = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
......
registerReceiver(batteryLevelReceiver, batteryLevelFilter);