jobscheduler/src/main/java/me/tatarka/support/internal/receivers/PowerReceiver.java
@Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (Intent.ACTION_BATTERY_LOW.equals(action)) {
            // If we get this action, the battery is discharging => it isn't plugged in so
            // there's no work to cancel. We track this variable for the case where it is
            // charging, but hasn't been for long enough to be healthy.
            ControllerPrefs.getInstance(context).edit().setBatteryLow(true).apply();
        } else if (Intent.ACTION_BATTERY_OKAY.equals(action)) {
            ControllerPrefs.getInstance(context).edit().setBatteryLow(false).apply();
            maybeReportNewChargingState(context, isCharging(context));
        } else if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
            // Set up an alarm for ACTION_CHARGING_STABLE - we don't want to kick off tasks
            // here if the user unplugs the phone immediately.
            setStableChargingAlarm(context);
        } else if (Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
            // If an alarm is set, breathe a sigh of relief and cancel it - crisis averted.
            cancelStableChargingAlarm(context);
            maybeReportNewChargingState(context, false);
        } else if (ACTION_CHARGING_STABLE.equals(action)) {
            // Here's where we actually do the notify for a task being ready.
            maybeReportNewChargingState(context, !isBatteryLow(context));
        }
    }
@Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (Intent.ACTION_BATTERY_LOW.equals(action)) {
            // If we get this action, the battery is discharging => it isn't plugged in so
            // there's no work to cancel. We track this variable for the case where it is
            // charging, but hasn't been for long enough to be healthy.
            ControllerPrefs.getInstance(context).edit().setBatteryLow(true).apply();
        } else if (Intent.ACTION_BATTERY_OKAY.equals(action)) {
            ControllerPrefs.getInstance(context).edit().setBatteryLow(false).apply();
            maybeReportNewChargingState(context, isCharging(context));
        } else if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
            // Set up an alarm for ACTION_CHARGING_STABLE - we don't want to kick off tasks
            // here if the user unplugs the phone immediately.
            setStableChargingAlarm(context);
        } else if (Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
            // If an alarm is set, breathe a sigh of relief and cancel it - crisis averted.
            cancelStableChargingAlarm(context);
            maybeReportNewChargingState(context, false);
        } else if (ACTION_CHARGING_STABLE.equals(action)) {
            // Here's where we actually do the notify for a task being ready.
            maybeReportNewChargingState(context, !isBatteryLow(context));
        }
    }
@ Override public void onReceive ( Context context , Intent intent ) { final String action = intent . getAction ( ) ; if ( Intent . ACTION_BATTERY_LOW . equals ( action ) ) { // If we get this action, the battery is discharging => it isn't plugged in so // there's no work to cancel. We track this variable for the case where it is // charging, but hasn't been for long enough to be healthy. ControllerPrefs . getInstance ( context ) . edit ( ) . setBatteryLow ( true ) . apply ( ) ; } else if ( Intent . ACTION_BATTERY_OKAY . equals ( action ) ) { ControllerPrefs . getInstance ( context ) . edit ( ) . setBatteryLow ( false ) . apply ( ) ; maybeReportNewChargingState ( context , isCharging ( context ) ) ; } else if ( Intent . ACTION_POWER_CONNECTED . equals ( action ) ) { // Set up an alarm for ACTION_CHARGING_STABLE - we don't want to kick off tasks // here if the user unplugs the phone immediately. setStableChargingAlarm ( context ) ; } else if ( Intent . ACTION_POWER_DISCONNECTED . equals ( action ) ) { // If an alarm is set, breathe a sigh of relief and cancel it - crisis averted. cancelStableChargingAlarm ( context ) ; maybeReportNewChargingState ( context , false ) ; } else if ( ACTION_CHARGING_STABLE . equals ( action ) ) { // Here's where we actually do the notify for a task being ready. maybeReportNewChargingState ( context , ! isBatteryLow ( context ) ) ; } }
private static final long STABLE_CHARGING_THRESHOLD_MILLIS = 1000; // 1 second.
private static final long STABLE_CHARGING_THRESHOLD_MILLIS = 1000 ; // 1 second .