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:net.ben.subsonic.androidapp.util.Util.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}

From source file:com.dmbstream.android.util.Util.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    boolean connected = networkInfo != null && networkInfo.isConnected();

    boolean wifiConnected = connected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
    boolean wifiRequired = isWifiRequiredForDownload(context);

    return connected && (!wifiRequired || wifiConnected);
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static boolean m963j(Context context) {
    if (context == null) {
        return false;
    }/*from  w  ww.  j  a va  2s  .  c om*/
    try {
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity"))
                .getActiveNetworkInfo();
        if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
            return false;
        }
        int type = activeNetworkInfo.getType();
        if (type == 1) {
            System.out.println("CONNECTED VIA WIFI");
            return true;
        }
        if (type == 0) {
            switch (activeNetworkInfo.getSubtype()) {
            case DetectedActivity.IN_VEHICLE /*0*/:
                return false;
            case DetectedActivity.ON_BICYCLE /*1*/:
                return false;
            case DetectedActivity.ON_FOOT /*2*/:
                return false;
            case DetectedActivity.STILL /*3*/:
                return true;
            case DetectedActivity.UNKNOWN /*4*/:
                return false;
            case DetectedActivity.TILTING /*5*/:
                return true;
            case GamesClient.STATUS_NETWORK_ERROR_OPERATION_FAILED /*6*/:
                return true;
            case GamesClient.STATUS_LICENSE_CHECK_FAILED /*7*/:
                return false;
            case NETWORK_TYPE_HSDPA /*8*/:
                return true;
            case NETWORK_TYPE_HSUPA /*9*/:
                return true;
            case NETWORK_TYPE_HSPA /*10*/:
                return true;
            case NETWORK_TYPE_IDEN /*11*/:
                return false;
            case NETWORK_TYPE_EVDO_B /*12*/:
                return true;
            case NETWORK_TYPE_LTE /*13*/:
                return true;
            case NETWORK_TYPE_EHRPD /*14*/:
                return true;
            case NETWORK_TYPE_HSPAP /*15*/:
                return true;
            default:
                return false;
            }
        }
        return false;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.android.aft.AFNetworkConnection.AFNetworkConnection.java

public static boolean isNetworkAvailable(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    // if no network is available networkInfo will be null
    // otherwise check if we are connected
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    }/*  w  ww.java  2s . co  m*/
    return false;
}

From source file:android_network.hetnet.vpn_service.Util.java

public static boolean isConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
    return (ni != null && ni.isConnected());
}

From source file:MainActivity.java

private boolean isOnline() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}

From source file:de.ub0r.android.websms.connector.common.Utils.java

/**
 * Checks if there is a data network available. Requires
 * ACCESS_NETWORK_STATE permission./*ww w. j  a v a2  s .  c  om*/
 * 
 * @param context
 *            {@link Context}
 * @return true if a data network is available
 */
public static boolean isNetworkAvailable(final Context context) {
    try {
        ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo net = mgr.getActiveNetworkInfo();
        return net != null && net.isConnected();
    } catch (SecurityException ex) {
        // for backwards compatibility, if the app has no
        // ACCESS_NETWORK_STATE permission then carry on
        return true;
    }
}

From source file:com.example.qrpoll.Refresh.java

/**
 * sprawdza, czy w urzadzeniu wlaczona jest obsluga danych pakietowych
 * @return/*from  w w w. j  a  v a  2  s  . c o  m*/
 */
public boolean checkNetwork() {
    ConnectivityManager cm = (ConnectivityManager) activity.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    return ni.isConnected();
}

From source file:jieehd.villain.updater.appUpdates.java

private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }// www . jav  a  2 s  .co m

    if (haveConnectedWifi == false && haveConnectedMobile == false) {
        Log.d("Network State", "false");
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:org.travey.travey.DataConnection.java

public boolean isConnected() {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected())
        return true;
    else/*from   ww w . j  a v  a  2s.com*/
        return false;
}