change check for wifi connection to metered connection
This commit is contained in:
parent
ef31878a10
commit
6f2bfed3a6
|
@ -76,7 +76,7 @@ import de.danoeh.antennapod.core.util.InvalidFeedException;
|
||||||
import de.greenrobot.event.EventBus;
|
import de.greenrobot.event.EventBus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the download of feedfiles in the app. Downloads can be enqueued viathe startService intent.
|
* Manages the download of feedfiles in the app. Downloads can be enqueued via the startService intent.
|
||||||
* The argument of the intent is an instance of DownloadRequest in the EXTRA_REQUEST field of
|
* The argument of the intent is an instance of DownloadRequest in the EXTRA_REQUEST field of
|
||||||
* the intent.
|
* the intent.
|
||||||
* After the downloads have finished, the downloaded object will be passed on to a specific handler, depending on the
|
* After the downloads have finished, the downloaded object will be passed on to a specific handler, depending on the
|
||||||
|
@ -199,10 +199,10 @@ public class DownloadService extends Service {
|
||||||
if(type == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
if(type == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
long id = status.getFeedfileId();
|
long id = status.getFeedfileId();
|
||||||
FeedMedia media = DBReader.getFeedMedia(id);
|
FeedMedia media = DBReader.getFeedMedia(id);
|
||||||
if(media == null || media.getItem() == null) {
|
FeedItem item;
|
||||||
|
if(media == null || (item = media.getItem()) == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FeedItem item = media.getItem();
|
|
||||||
boolean httpNotFound = status.getReason() == DownloadError.ERROR_HTTP_DATA_ERROR
|
boolean httpNotFound = status.getReason() == DownloadError.ERROR_HTTP_DATA_ERROR
|
||||||
&& String.valueOf(HttpURLConnection.HTTP_NOT_FOUND).equals(status.getReasonDetailed());
|
&& String.valueOf(HttpURLConnection.HTTP_NOT_FOUND).equals(status.getReasonDetailed());
|
||||||
boolean forbidden = status.getReason() == DownloadError.ERROR_FORBIDDEN
|
boolean forbidden = status.getReason() == DownloadError.ERROR_FORBIDDEN
|
||||||
|
@ -221,7 +221,11 @@ public class DownloadService extends Service {
|
||||||
// so that lists reload that it
|
// so that lists reload that it
|
||||||
if(status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
if(status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
|
FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
|
||||||
EventBus.getDefault().post(FeedItemEvent.updated(media.getItem()));
|
FeedItem item;
|
||||||
|
if(media == null || (item = media.getItem()) == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EventBus.getDefault().post(FeedItemEvent.updated(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queryDownloadsAsync();
|
queryDownloadsAsync();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.support.v4.net.ConnectivityManagerCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
@ -80,16 +81,13 @@ public class NetworkUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDownloadAllowed() {
|
public static boolean isDownloadAllowed() {
|
||||||
return UserPreferences.isAllowMobileUpdate() || NetworkUtils.connectedToWifi();
|
return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean connectedToWifi() {
|
public static boolean isNetworkMetered() {
|
||||||
ConnectivityManager connManager = (ConnectivityManager) context
|
ConnectivityManager connManager = (ConnectivityManager) context
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
NetworkInfo mWifi = connManager
|
return ConnectivityManagerCompat.isActiveNetworkMetered(connManager);
|
||||||
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
|
||||||
|
|
||||||
return mWifi.isConnected();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue