mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-23 15:21:07 +01:00
Added Connectivity change receiver
This commit is contained in:
parent
485f8905c4
commit
6eb08f6693
@ -348,6 +348,11 @@
|
||||
android:configChanges="orientation"
|
||||
android:label="@string/organize_queue_label" >
|
||||
</activity>
|
||||
<receiver android:name=".receiver.ConnectivityActionReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user