Example usage for android.net ConnectivityManager getAllNetworkInfo

List of usage examples for android.net ConnectivityManager getAllNetworkInfo

Introduction

In this page you can find the example usage for android.net ConnectivityManager getAllNetworkInfo.

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@NonNull
public NetworkInfo[] getAllNetworkInfo() 

Source Link

Document

Returns connection status information about all network types supported by the device.

Usage

From source file:Main.java

public static boolean isNetworkAvailable(ConnectivityManager obj) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = obj;
    NetworkInfo[] mNetInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : mNetInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }// w w  w.j av a  2  s  . co  m
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

public static boolean isNetConnected(ConnectivityManager cm) {
    if (cm != null) {
        NetworkInfo[] infos = cm.getAllNetworkInfo();
        if (infos != null) {
            for (NetworkInfo ni : infos) {
                if (ni.isConnected()) {
                    return true;
                }/* w w w.ja va  2 s.c o m*/
            }
        }
    }
    return false;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static NetworkInfo[] getAllNetworkInfo(Context context) {
    ConnectivityManager connectivityManager = getConnectivityManager(context);
    if (connectivityManager != null) {
        return connectivityManager.getAllNetworkInfo();
    }/* w  ww  .  j a va  2s  .co  m*/
    return null;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] info = mgr.getAllNetworkInfo();
    if (info != null) {
        for (int i = 0; i < info.length; i++) {
            if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                return true;
            }/*w  w  w. java2  s .co m*/
        }
    }
    return false;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] info = mgr.getAllNetworkInfo();
    if (info != null) {
        for (NetworkInfo anInfo : info) {
            if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
                return true;
            }// ww w  .j av  a2  s. c  o  m
        }
    }
    return false;
}

From source file:Main.java

public static boolean checkConnection(Activity a) {
    boolean hasConnectedWifi = false;
    boolean hasConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("wifi"))
            if (ni.isConnected())
                hasConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("mobile"))
            if (ni.isConnected())
                hasConnectedMobile = true;
    }/*from   w w  w  .ja  v  a 2 s .  co  m*/
    return hasConnectedWifi || hasConnectedMobile;
}

From source file:Main.java

public static boolean haveNetworkConnection(Context context) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }/*from  ww  w.j av  a 2  s .com*/
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }/*ww w  .  j a  v a  2s . c  om*/
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

/**
 * Checks whether the device is connected to a network
 *//*  ww w.  j a v a 2s  .  com*/
public static boolean hasInternet(Activity a) {
    boolean hasConnectedWifi = false;
    boolean hasConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("wifi"))
            if (ni.isConnected())
                hasConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("mobile"))
            if (ni.isConnected())
                hasConnectedMobile = true;
    }
    return hasConnectedWifi || hasConnectedMobile;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo[] networkInfos = conMgr.getAllNetworkInfo();
    for (NetworkInfo networkInfo : networkInfos) {
        if (networkInfo.getState() == NetworkInfo.State.CONNECTED
                || networkInfo.getState() == NetworkInfo.State.CONNECTING) {
            return true;
        }//from  ww w  . j av  a2  s.  co  m
    }
    return false;
}