Example usage for android.net NetworkInfo isConnectedOrConnecting

List of usage examples for android.net NetworkInfo isConnectedOrConnecting

Introduction

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

Prototype

@Deprecated
public boolean isConnectedOrConnecting() 

Source Link

Document

Indicates whether network connectivity exists or is in the process of being established.

Usage

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

From source file:Main.java

/**
 * This checks the system-side for network connectivity, then pings the google
 * server to make sure they have internet connection. One other method avail here for use
 * in checking via ConnectivityManager.//from  ww w.j a v a 2  s. c o  m
 * @param context Context to be passed
 * @return Returns a boolean, true if they have internet, false if they do not.
 */
public static boolean haveNetworkConnection3(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isNetConnected(Context context) {
    if (context == null) {
        return true;
    }/*from w  w  w  . j av a  2  s  . c  om*/
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nwInfo = connectivityManager.getActiveNetworkInfo();
    if (nwInfo != null && nwInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}

From source file:Main.java

public static int disconnectWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (ni != null && ni.isConnectedOrConnecting()) {
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        int id = wm.getConnectionInfo().getNetworkId();
        return wm.disconnect() ? id : -1;
    }/*from  ww  w.  j  a v  a2s  . c  o m*/

    return -1;
}

From source file:Main.java

/**
 * test if there is some connection//from   w ww  . j a v  a  2  s . c  om
 * @param ctx
 * @return
 */
public static boolean verifyConnectivity(Context ctx) {

    ConnectivityManager connectivityManager = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

From source file:Main.java

/**
 * Checks if Android is online/*from w  w w.  j a v  a 2 s  .c o m*/
 *
 * @param context
 * @return returns true if online
 */
public static boolean isAndroidOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    return isConnected;
}

From source file:Main.java

public static boolean isNetConnected(Context context) {
    if (context != null) {
        final ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        return !(networkInfo == null || !networkInfo.isConnectedOrConnecting());
    } else {//from  w  w  w  .j a va 2s  .co m
        return false;
    }
}

From source file:Main.java

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

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    return isConnected;
}