Example usage for android.net NetworkInfo isAvailable

List of usage examples for android.net NetworkInfo isAvailable

Introduction

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

Prototype

@Deprecated
public boolean isAvailable() 

Source Link

Document

Indicates whether network connectivity is possible.

Usage

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    boolean resp = false;
    final ConnectivityManager connMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connMgr.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.isAvailable()) {
        resp = true;/*w  ww  .  j a  v a  2 s  .c  o  m*/
    }
    return resp;
}

From source file:Main.java

public static boolean checkNetworkStatus(Context context) {
    boolean resp = false;
    final ConnectivityManager connMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connMgr.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.isAvailable()) {
        resp = true;// w  ww .  j  av  a 2  s.c  o  m
    }
    return resp;
}

From source file:Main.java

public static Boolean isNetworkConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }//from  w ww  .  jav  a 2  s .  c  o  m
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }
    return true;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    if (context != null) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        if (info != null) {
            return info.isAvailable();
        }//from   ww  w.j a  v a2 s. c om
    }
    return false;
}

From source file:Main.java

public static boolean checkNet(Activity act) {
    ConnectivityManager manager = (ConnectivityManager) act.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }/*from w ww.j a  va2  s  .  c  o m*/
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }
    return true;
}

From source file:Main.java

public static boolean hasNetwork(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }/*  w  w w . j a  va2s. c  om*/
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }
    return true;

}

From source file:Main.java

public static boolean isNetworkReachable(Context mContext) {
    boolean bRet = false;
    try {/*  w  w  w.  j a v  a2  s. c o m*/
        ConnectivityManager conn = (ConnectivityManager) mContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = conn.getActiveNetworkInfo();
        bRet = (null == netInfo) ? false : netInfo.isAvailable();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bRet;
}

From source file:Main.java

public static boolean isWifiAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return wifiNetworkInfo.isAvailable();

}

From source file:Main.java

/**
 * @param context/*  ww  w.  j  a  v  a  2  s . c o m*/
 * @return boolean
 * @throws
 * @Title: isNetworkAvailable
 * @Description: TODO
 */
public static boolean isNetworkAvailable(Context context) {
    if (checkPermission(context, "android.permission.INTERNET")) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (ni != null && ni.isAvailable()) {
            return true;
        }
        return false;
    }
    return false;
}

From source file:Main.java

public static int getConnectedType(Context context) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
    if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
        return mNetworkInfo.getType();
    }/* w  w  w.java2s. c om*/
    return -1;
}