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:com.fede.Utilities.GeneralUtils.java

public static boolean isNetworkAvailable(Context context) {
    boolean value = false;
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info != null && info.isAvailable()) {
        value = true;//from ww w . j a v a 2  s.  co m
    }
    return value;
}

From source file:com.amazonaws.utilities.Util.java

public static boolean isOnline(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivity.getActiveNetworkInfo();
    if (activeNetworkInfo != null) {
        boolean networkAvailable = activeNetworkInfo.isAvailable();
        boolean networkConnected = activeNetworkInfo.isConnected();
        if (networkAvailable && networkConnected) {
            return true;
        } else {// w w w.  j  a v a2s  . c  o m
            return false;
        }
    } else {
        return false;
    }
}

From source file:edu.mecc.race2ged.helpers.Utils.java

/**
 * Are we connected to WiFi, Mobile Data, or nothing?
 * @return The devices current network state.
 *///from   www.  j a v  a2 s. co  m
public static int getNetworkStatus(Context context) {
    final ConnectivityManager connMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (wifi != null && wifi.isAvailable() && wifi.isConnected())
        return WIFI;
    else if (mobile != null && mobile.isAvailable() && mobile.isConnected())
        return MOBILE_DATA;
    return NO_CONNECTION;
}

From source file:com.ichi2.async.Connection.java

public static boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) AnkiDroidApp.getInstance().getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo == null || !netInfo.isConnected() || !netInfo.isAvailable()) {
        return false;
    }//www  .  j  a  v  a 2 s. com
    return true;
}

From source file:com.wbtech.common.CommonUtil.java

/**
 * ?   ?wifi/*from  w w w . j av  a2  s  . c  o m*/
 * @param context
 * @return
 */
public static boolean isNetworkTypeWifi(Context context) {
    // TODO Auto-generated method stub

    if (checkPermissions(context, "android.permission.INTERNET")) {
        ConnectivityManager cManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cManager.getActiveNetworkInfo();

        if (info != null && info.isAvailable() && info.getTypeName().equals("WIFI")) {
            return true;
        } else {
            if (UmsConstants.DebugMode) {
                Log.e("error", "Network not wifi");
            }
            return false;
        }
    } else {
        if (UmsConstants.DebugMode) {
            Log.e(" lost  permission", "lost----> android.permission.INTERNET");
        }
        return false;
    }

}

From source file:com.wbtech.common.CommonUtil.java

/**
 * ??/*from www. j  av  a2 s.co m*/
 * 
 * @param context
 * @return true ?  false ?
 */
public static boolean isNetworkAvailable(Context context) {
    if (checkPermissions(context, "android.permission.INTERNET")) {
        ConnectivityManager cManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cManager.getActiveNetworkInfo();

        //            if (info != null && info.isAvailable()&&info.getTypeName().equals("WIFI")){ 
        if (info != null && info.isAvailable()) {
            return true;
        } else {
            if (UmsConstants.DebugMode) {
                Log.e("error", "Network error");
            }

            return false;
        }

    } else {
        if (UmsConstants.DebugMode) {
            Log.e(" lost  permission", "lost----> android.permission.INTERNET");
        }

        return false;
    }

}

From source file:com.bbxiaoqu.api.util.Utils.java

/**
 * Proxy//ww w .  j  av a  2s.  c o m
 */
public static HttpHost detectProxy(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni != null && ni.isAvailable() && ni.getType() == ConnectivityManager.TYPE_MOBILE) {
        String proxyHost = android.net.Proxy.getDefaultHost();
        int port = android.net.Proxy.getDefaultPort();
        if (proxyHost != null) {
            return new HttpHost(proxyHost, port, "http");
        }
    }
    return null;
}

From source file:website.openeng.async.Connection.java

public static boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) KanjiDroidApp.getInstance().getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo == null || !netInfo.isConnected() || !netInfo.isAvailable()) {
        return false;
    }/*from   w  w  w  .j  a  v  a 2s  . co m*/
    return true;
}

From source file:org.brandroid.openmanager.fragments.DialogHandler.java

public static String getNetworkInfo(Context c) {
    String ret = getNetworkInterfaces();

    ConnectivityManager conman = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (conman == null)
        ret += "No Connectivity?\n";
    else {/* www.j  a v a  2  s  . c  o  m*/
        ret += "Connectivity Info:\n" + conman.toString() + "\n";
        for (NetworkInfo ni : conman.getAllNetworkInfo()) {
            if (!ni.isAvailable())
                continue;
            ret += "Network [" + ni.getTypeName() + "]: " + getNetworkInfoInfo(ni) + "\n";
        }
    }
    try {
        WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
        if (wifi == null)
            ret += "No wifi\n";
        else {
            ret += "Wifi Info:\n" + wifi.toString() + "\n";
            ret += "Status: " + (wifi.isWifiEnabled() ? "ENABLED" : "DISABLED") + "\n";
            ret += "ip=" + getReadableIP(wifi.getConnectionInfo().getIpAddress()) + "/ " + "mac="
                    + wifi.getConnectionInfo().getMacAddress() + "/ " + "b="
                    + wifi.getConnectionInfo().getBSSID() + "/ " + "s=" + wifi.getConnectionInfo().getSSID();
            DhcpInfo dh = wifi.getDhcpInfo();
            if (dh == null)
                ret += "No DHCP\n";
            else {
                ret += "IP: " + getReadableIP(dh.ipAddress) + "\n";
                ret += "Gateway: " + getReadableIP(dh.gateway) + "\n";
                ret += "DNS: " + getReadableIP(dh.dns1) + " " + getReadableIP(dh.dns2) + "\n";
            }
        }
    } catch (SecurityException sec) {
        ret += "No Wifi permissions.\n";
    }
    return ret;
}

From source file:util.Utils.java

/**
 * ??/*ww w.  j  a  v a2  s  .  c  om*/
 *
 * @param context 
 * @return ??
 */
public static boolean isNetworkConnected(Context context) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
    if (mNetworkInfo != null) {
        return mNetworkInfo.isAvailable();
    }
    return false;
}