Android Utililty Methods Network State Check

List of utility methods to do Network State Check

Description

The list of methods to do Network State Check are organized into topic(s).

Method

booleanisConnected(Context context)
is Connected
NetworkInfo info = getNetworkInfo(context);
return isConnected(info);
booleanisConnected(Context context)
is Connected
ConnectivityManager manager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager.getActiveNetworkInfo() != null
        && manager.getActiveNetworkInfo().isAvailable()
        && manager.getActiveNetworkInfo().isConnected())
    return true;
return false;
booleanisConnected(Context context)
Check if there is any connectivity
NetworkInfo info = Connectivity.getNetworkInfo(context);
return (info != null && info.isConnected());
booleanisConnected(NetworkInfo info)
is Connected
return info != null && info.isConnected();
booleanisConnected(final Context context, final int... networkTypes)
is Connected
final ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (networkTypes.length > 0)
    for (final int networkType : networkTypes)
        if (ConnectivityManager.isNetworkTypeValid(networkType))
            return isConnected(connectivity
                    .getNetworkInfo(networkType));
return isConnected(connectivity.getActiveNetworkInfo());
...
booleanisConnected(final NetworkInfo info)
is Connected
return null != info && info.isConnected();
booleanisConnectedFast(Context context)
Check if there is fast connectivity
NetworkInfo info = Connectivity.getNetworkInfo(context);
return (info != null && info.isConnected() && Connectivity
        .isConnectionFast(info.getType(), info.getSubtype()));
booleanisConnectedMobile(Context context)
is Connected Mobile
NetworkInfo info = getNetworkInfo(context);
return isConnected(info)
        && info.getType() == ConnectivityManager.TYPE_MOBILE;
booleanisConnectedMobile(Context context)
Check if there is any connectivity to a mobile network
NetworkInfo info = Connectivity.getNetworkInfo(context);
return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_MOBILE);
booleanisConnectingToInternet()
is Connecting To Internet
ConnectivityManager connectivity = (ConnectivityManager) _context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
    NetworkInfo[] info = connectivity.getAllNetworkInfo();
    if (info != null)
        for (int i = 0; i < info.length; i++)
            if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                return true;
...