如果您运行此代码,那么isCharging
会在充电时及其充满时给出什么回报?
public void onReceive(Context context, Intent intent) {
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
}
答案 0 :(得分:3)
isCharging
将为true
。