Example usage for android.net NetworkInfo isConnected

List of usage examples for android.net NetworkInfo isConnected

Introduction

In this page you can find the example usage for android.net NetworkInfo isConnected.

Prototype

@Deprecated
public boolean isConnected() 

Source Link

Document

Indicates whether network connectivity exists and it is possible to establish connections and pass data.

Usage

From source file:Main.java

public static boolean isNetworkAvailable(Activity a) {
    ConnectivityManager connectivityManager = (ConnectivityManager) a.getSystemService(a.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetworkInfo.isConnected()) {
        return true;
    }//from  w  w w .j a  va2s. co m
    return false;
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {

    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
    if (activeInfo != null) {
        return activeInfo.isConnected();
    }/*from  w  ww. ja v a 2s.  c  om*/
    return false;
}

From source file:Main.java

public static boolean isConnectionAvailable(final Context context) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

    return networkInfo != null && networkInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkAvailable(final Context context) {
    if (context != null) {
        final ConnectivityManager connManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo info = connManager.getActiveNetworkInfo();
        return info != null && info.isConnected();
    }// w  w  w.j a  va 2  s .c  o m
    return false;
}

From source file:Main.java

/**
 * Returns network availability status./*from ww  w.  ja  va2s .co m*/
 * @param context - Application context.
 * @return - Network availability status.
 */
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectivityManager.getActiveNetworkInfo();
    return info != null && info.isConnected();
}

From source file:Main.java

/**
 * <pre>//  w  w w. j a  v a2  s. c  o  m
 * Determine whether network is currently connected.
 * </pre>
 */
public static boolean isNetworkConnected() {
    ConnectivityManager conMan = (ConnectivityManager) getCurrentContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = conMan.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnected();
}

From source file:Main.java

public static String getCurrentSsid(Context context) {
    String ssid = null;/*from  ww w.  j  a va2s .  com*/
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfo.isConnected()) {
        final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        if (connectionInfo != null && connectionInfo.getSSID() != null
                && !connectionInfo.getSSID().equals("")) {
            ssid = connectionInfo.getSSID();
        }
    }
    return ssid == null ? ssid : ssid.replace("\"", "");
}

From source file:Main.java

public static boolean isConnectedRoaming(Context context) {
    ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (mobile != null && mobile.isConnected() && mobile.isRoaming()) {
        return true;
    } else {//from   w w w  . j  a v  a  2s  .  c  o  m
        return false;
    }
}

From source file:Main.java

public static boolean isNetworkAvailableAndConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}