package com.marshalchen.common.commonUtils.networkUtils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
* Check network status
*/
public class BasicNetworkUtils {
/**
* Check if the device has connected network.
* @param context
* @return
*/
public static boolean checkNetwork(Context context) {
ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo net = conn.getActiveNetworkInfo();
if (net != null && net.isConnected()) {
return true;
}
return false;
}
/**
* Check the network is Wifi or not
* @param context
* @return
*/
public static boolean isWifiConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWiFiNetworkInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWiFiNetworkInfo != null) {
return mWiFiNetworkInfo.isAvailable();
}
}
return false;
}
}