Skip to content

Commit

Permalink
Use a few API15 fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
ened committed Apr 7, 2015
1 parent f8235ff commit c5b5681
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public class NetworkUtils {

final private static Logger log = Logger.getLogger(NetworkUtils.class.getName());

private final static int CONNECTIVITY_TYPE_WIMAX = 6; // Since API 8
private final static int CONNECTIVITY_TYPE_ETHERNET = 9; // Since API 13

static public NetworkInfo getConnectedNetworkInfo(Context context) {

ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Expand All @@ -49,10 +46,10 @@ static public NetworkInfo getConnectedNetworkInfo(Context context) {
networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) return networkInfo;

networkInfo = connectivityManager.getNetworkInfo(CONNECTIVITY_TYPE_WIMAX);
networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIMAX);
if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) return networkInfo;

networkInfo = connectivityManager.getNetworkInfo(CONNECTIVITY_TYPE_ETHERNET);
networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) return networkInfo;

log.info("Could not find any connected network...");
Expand All @@ -61,15 +58,15 @@ static public NetworkInfo getConnectedNetworkInfo(Context context) {
}

static public boolean isEthernet(NetworkInfo networkInfo) {
return isNetworkType(networkInfo, CONNECTIVITY_TYPE_ETHERNET);
return isNetworkType(networkInfo, ConnectivityManager.TYPE_ETHERNET);
}

static public boolean isWifi(NetworkInfo networkInfo) {
return isNetworkType(networkInfo, ConnectivityManager.TYPE_WIFI) || ModelUtil.ANDROID_EMULATOR;
}

static public boolean isMobile(NetworkInfo networkInfo) {
return isNetworkType(networkInfo, ConnectivityManager.TYPE_MOBILE) || isNetworkType(networkInfo, CONNECTIVITY_TYPE_WIMAX);
return isNetworkType(networkInfo, ConnectivityManager.TYPE_MOBILE) || isNetworkType(networkInfo, ConnectivityManager.TYPE_WIMAX);
}

static public boolean isNetworkType(NetworkInfo networkInfo, int type) {
Expand Down

0 comments on commit c5b5681

Please sign in to comment.