Android Network State Check isConnected(final Context context, final int... networkTypes)

Here you can find the source of isConnected(final Context context, final int... networkTypes)

Description

is Connected

License

Open Source License

Declaration

public static final boolean isConnected(final Context context,
            final int... networkTypes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    public static final boolean isConnected(final Context context,
            final int... networkTypes) {
        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());
    }/*from w  w w .  j a va  2s .c o  m*/

    private static boolean isConnected(final NetworkInfo info) {
        return null != info && info.isConnected();
    }
}

Related

  1. hasNoConnectivity(Application application)
  2. isConnected(Context context)
  3. isConnected(Context context)
  4. isConnected(Context context)
  5. isConnected(NetworkInfo info)
  6. isConnected(final NetworkInfo info)
  7. isConnectedFast(Context context)
  8. isConnectedMobile(Context context)
  9. isConnectedMobile(Context context)