diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-03-09 21:08:24 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-03-09 21:08:24 +0100 |
commit | 6eb08f6693d91da323b57c2790d9abed0a60d182 (patch) | |
tree | 56852734e26c922bd826706d53176cce3d591be4 /src | |
parent | 485f8905c434f1422728c30bf84c115e74cc502c (diff) | |
download | AntennaPod-6eb08f6693d91da323b57c2790d9abed0a60d182.zip |
Added Connectivity change receiver
Diffstat (limited to 'src')
-rw-r--r-- | src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java b/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java new file mode 100644 index 000000000..5c898384a --- /dev/null +++ b/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java @@ -0,0 +1,49 @@ +package de.danoeh.antennapod.receiver; + +import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.feed.FeedManager; +import de.danoeh.antennapod.storage.DownloadRequester; +import de.danoeh.antennapod.util.NetworkUtils; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.util.Log; + +public class ConnectivityActionReceiver extends BroadcastReceiver { + private static final String TAG = "ConnectivityActionReceiver"; + + @Override + public void onReceive(final Context context, Intent intent) { + if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { + if (AppConfig.DEBUG) + Log.d(TAG, "Received intent"); + + if (NetworkUtils.autodownloadNetworkAvailable(context)) { + if (AppConfig.DEBUG) + Log.d(TAG, + "auto-dl network available, starting auto-download"); + new Thread() { + @Override + public void run() { + FeedManager.getInstance() + .autodownloadUndownloadedItems(context); + } + }.start(); + } else { // if new network is Wi-Fi, finish ongoing downloads, + // otherwise cancel all downloads + ConnectivityManager cm = (ConnectivityManager) context + .getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo ni = cm.getActiveNetworkInfo(); + if (ni == null || ni.getType() != ConnectivityManager.TYPE_WIFI) { + if (AppConfig.DEBUG) + Log.i(TAG, + "Device is no longer connected to Wi-Fi. Cancelling ongoing downloads"); + DownloadRequester.getInstance().cancelAllDownloads(context); + } + + } + } + } +} |