这个对吗?我正在修改来自 github 的源代码:USB CHARGE COMMANDER 当电池电量从 20% 下降时,它会在电池电量下降 80 时充电,它不会和倒数计时器每 5 分钟执行一次我设置 20000 只是为了测试
boolean startcountdown=true;
do{
new CountDownTimer(20000, 1000) {
Intent intent = _context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
int percent = (level*100)/scale;
public void onTick(long millisUntilFinished) {}
public void onFinish() {
if(percent <= 20){
_iIsCharging = 1;
}
else if (percent >=80){
_iIsCharging = 0;
}
else{
_iIsCharging = 1;
}
}
}.start();
}while(startcountdown);