From abdf9a3f2839fdde04a1c0096705897497b4bebe Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Thu, 26 Mar 2015 21:17:41 -0400 Subject: for some reason the intent doesn't have EXTRA_STATUS anymore. We'll just see what the action type is. closes #695 --- .../danoeh/antennapod/receiver/PowerConnectionReceiver.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/de/danoeh/antennapod') diff --git a/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java b/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java index 0e7784381..f050e031d 100644 --- a/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java +++ b/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java @@ -13,16 +13,19 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; // modified from http://developer.android.com/training/monitoring-device-state/battery-monitoring.html // and ConnectivityActionReceiver.java +// Updated based on http://stackoverflow.com/questions/20833241/android-charge-intent-has-no-extra-data +// Since the intent doesn't have the EXTRA_STATUS like the android.com article says it does +// (though it used to) public class PowerConnectionReceiver extends BroadcastReceiver { private static final String TAG = "PowerConnectionReceiver"; @Override public void onReceive(Context context, Intent intent) { - int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); - boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || - status == BatteryManager.BATTERY_STATUS_FULL; + final String action = intent.getAction(); - if (isCharging) { + Log.d(TAG, "charging intent: " + action); + + if (Intent.ACTION_POWER_CONNECTED.equals(action)) { Log.d(TAG, "charging, starting auto-download"); // we're plugged in, this is a great time to auto-download if everything else is // right. So, even if the user allows auto-dl on battery, let's still start -- cgit v1.2.3