@Test @SmallTest @SdkSuppress(minSdkVersion = 23) public void testGetIntentFilter_afterApi23() { IntentFilter intentFilter = mTracker.getIntentFilter(); assertThat(intentFilter.hasAction(BatteryManager.ACTION_CHARGING), is(true)); assertThat(intentFilter.hasAction(BatteryManager.ACTION_DISCHARGING), is(true)); assertThat(intentFilter.countActions(), is(2)); }
@Override public IntentFilter getIntentFilter() { IntentFilter intentFilter = new IntentFilter(); if (Build.VERSION.SDK_INT >= 23) { intentFilter.addAction(BatteryManager.ACTION_CHARGING); intentFilter.addAction(BatteryManager.ACTION_DISCHARGING); } else { intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); } return intentFilter; }
BatteryChargingTracker extends BroadcastReceiverConstraintTracker<Boolean> { @Override public IntentFilter getIntentFilter() { IntentFilter intentFilter = new IntentFilter(); if (Build.VERSION.SDK_INT >= 23) { intentFilter.addAction(BatteryManager.ACTION_CHARGING); intentFilter.addAction(BatteryManager.ACTION_DISCHARGING); } else { intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); } return intentFilter; } }
BatteryChargingTracker extends BroadcastReceiverConstraintTracker<Boolean> { @Override public IntentFilter getIntentFilter() { IntentFilter intentFilter = new IntentFilter(); if (Build.VERSION.SDK_INT >= 23) { intentFilter.addAction(BatteryManager.ACTION_CHARGING); intentFilter.addAction(BatteryManager.ACTION_DISCHARGING); } else { intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); } return intentFilter; } BatteryChargingTracker(Context context); }
BatteryChargingTracker extends BroadcastReceiverConstraintTracker<Boolean> { @Override public IntentFilter getIntentFilter() { IntentFilter intentFilter = new IntentFilter(); if (Build.VERSION.SDK_INT >= 23) { intentFilter.addAction(BatteryManager.ACTION_CHARGING); intentFilter.addAction(BatteryManager.ACTION_DISCHARGING); } else { intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); } return intentFilter; } BatteryChargingTracker(Context context); @Override Boolean getInitialState(); @Override IntentFilter getIntentFilter(); @Override void onBroadcastReceive(Context context, @NonNull Intent intent); }
BatteryChargingTracker extends BroadcastReceiverConstraintTracker<Boolean> { @Override public IntentFilter getIntentFilter() { IntentFilter intentFilter = new IntentFilter(); if (Build.VERSION.SDK_INT >= 23) { intentFilter.addAction(BatteryManager.ACTION_CHARGING); intentFilter.addAction(BatteryManager.ACTION_DISCHARGING); } else { intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); } return intentFilter; } BatteryChargingTracker(Context context); @Override Boolean getInitialState(); @Override IntentFilter getIntentFilter(); @Override void onBroadcastReceive(Context context, @NonNull Intent intent);  }