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:com.aegiswallet.utils.BasicUtils.java

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

From source file:org.basdroid.common.NetworkUtils.java

public static boolean isLTE(Context context) {
    NetworkInfo info = getNetworkInfo(context);
    if (info == null || !info.isConnected()) {
        return false;
    }//from  w w  w.j  a v a 2s . c  o  m

    int type = info.getType();
    int subType = info.getSubtype();

    if (type == ConnectivityManager.TYPE_WIFI) {
        return false;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return false; // ~ 50-100 kbps
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
         * to appropriate level to use these
         */
        case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
        case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
        case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
        case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
            return true; // ~ 10+ Mbps
        // Unknown
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.lol.reddit.common.General.java

public static boolean isConnectionWifi(final Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return info != null && info.isConnected();
}

From source file:com.nextgis.firereporter.HttpGetter.java

static boolean IsNetworkAvailible(Context c) {
    ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);

    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null /*|| !cm.getBackgroundDataSetting()*/)
        return false;

    int netType = info.getType();
    //int netSubtype = info.getSubtype();
    if (netType == ConnectivityManager.TYPE_WIFI) {
        return info.isConnected();
    } else if (netType == ConnectivityManager.TYPE_MOBILE && /*netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
                                                             &&*/ !tm.isNetworkRoaming()) {
        return info.isConnected();
    } else {/*  www .  j  a v  a 2s  .c  o  m*/
        return false;
    }
}

From source file:com.sckftr.android.utils.net.Network.java

/**
 * Check network connected.//from  w w  w.j a v  a2s  .  c o  m
 *
 * @throws NetworkConnectionException
 *             the network error exception
 * @param context
        
 */
public static boolean checkConnected(Context context) {

    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo netInfo = connManager.getActiveNetworkInfo();

    if ((netInfo == null) || !netInfo.isConnected()) {
        return false;
        //throw new NetworkConnectionException();
    }
    return true;

    //  if ( !connManager.requestRouteToHost(netInfo.getType(),
    // lookupHost(host)) ) {
    // throw new RemoteException();
    // }
    /*
     * try { if
     * (InetAddress.getByName(host).isReachable(HOST_REACHABILITY_TIMEOUT)){
     * throw new RemoteException(); } } catch (UnknownHostException e) {
     * throw new RemoteException(); } catch (IOException e) { throw new
     * RemoteException(); }
     */

}

From source file:fr.cph.chicago.util.Util.java

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

From source file:com.popcorntime.apps.remote.utils.Utils.java

public static boolean isWIFIConnected(Context context) {
    ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi != null && mWifi.isConnected())
        return true;

    return false;
}

From source file:com.yibu.kuaibu.app.glApplication.java

public static boolean isOnline() {
    ConnectivityManager connMgr = (ConnectivityManager) instance.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}

From source file:com.matze5800.paupdater.Functions.java

public static boolean WifiConnected(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return mWifi.isConnected();
}

From source file:com.normalexception.app.rx8club.html.LoginFactory.java

/**
 * Check to see if a network connection exists
 * @return   True if network connection exists
 *///from  w  w w  .j  a  va  2  s .c  o m
public static boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;
    boolean haveConnectedEth = false;

    Log.d(TAG, "Checking available network connections");
    ConnectivityManager cm = (ConnectivityManager) MainApplication.getAppContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        Log.d(TAG, String.format("%s is %sconnected", ni.getTypeName(), ni.isConnected() ? "" : "not "));
        if (ni.getTypeName().equalsIgnoreCase(LoginFactory.NETWORK_WIFI))
            if (ni.isConnected()) {
                Log.d(TAG, "Wifi Connection Detected");
                haveConnectedWifi = true;
            }
        if (ni.getTypeName().equalsIgnoreCase(LoginFactory.NETWORK_MOBILE))
            if (ni.isConnected()) {
                Log.d(TAG, "Mobile Connection Detected");
                haveConnectedMobile = true;
            }
        if (ni.getTypeName().equalsIgnoreCase(LoginFactory.NETWORK_ETH)
                || ni.getTypeName().equalsIgnoreCase(LoginFactory.NETWORK_ETHERNET))
            if (ni.isConnected()) {
                Log.d(TAG, "Ethernet Connection Detected");
                haveConnectedEth = true;
            }
    }
    return haveConnectedWifi || haveConnectedMobile || haveConnectedEth;
}