-4

如果您运行此代码,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;
}
4

1 回答 1

3

isChargingtrue如果满足其中任何一个条件,就会出现。

于 2013-03-29T16:30:19.933 回答