BatteryStatus isCharging给出了什么?

时间:2013-03-29 16:27:32

标签: java android

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

1 个答案:

答案 0 :(得分:3)

如果满足其中任何一个条件,

isCharging将为true