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 isNetworkOk(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    } else {/*  w  w w  . ja  va2s  .  c  o  m*/
        Toast.makeText(context, "Network is disconnected", Toast.LENGTH_SHORT).show();
        return false;
    }
}

From source file:Main.java

public static boolean isNetworkAvailable(Context ctx) {
    ConnectivityManager connectivityManager = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo inetInfo = connectivityManager.getActiveNetworkInfo();
    return inetInfo != null && inetInfo.isConnected();
}

From source file:Main.java

/**
 * Checks whether application has Internet connection.
 *///from w  w  w  . j  av  a  2s  .  co  m
public static boolean isConnected(Activity a) {
    ConnectivityManager connMgr = (ConnectivityManager) a.getSystemService(Activity.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected())
        return true;
    else
        return false;
}

From source file:Main.java

/**
 * Check network connectivity/*w w w  .j  a va 2  s .c  o  m*/
 *
 * @param context
 * */
public static boolean isConnected(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected())
        return true;
    else
        return false;
}

From source file:Main.java

public static boolean isNetworkConnected(Activity activity) {
    ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static Boolean NetWorkIsWifi(Context mContext) {
    boolean netStatus = false;
    ConnectivityManager connManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi.isConnected()) {
        netStatus = true;//www  .j av a2  s  . c  o m

    }
    return netStatus;

}

From source file:Main.java

static public boolean isNetworkConnectionAvailable(ConnectivityManager connectivityManager) {
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return null != networkInfo && networkInfo.isConnected();
}

From source file:Main.java

/**
 * Checked the network connect status./*from  w  w  w  .j  a v  a  2  s . c o  m*/
 */
public static boolean isNetworkConnected(Context context) {
    if (context == null) {
        return false;
    }

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return wifiInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        Log.v(TAG, " ConnectivityManager: " + " " + "networkInfo.isConnected()");
        return true;
    } else {/* w  w  w .  j a va2  s .c om*/
        Log.v(TAG, " ConnectivityManager: " + " " + "networkInfo = null");
        return false;
    }
}