Example usage for android.net NetworkInfo isConnectedOrConnecting

List of usage examples for android.net NetworkInfo isConnectedOrConnecting

Introduction

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

Prototype

@Deprecated
public boolean isConnectedOrConnecting() 

Source Link

Document

Indicates whether network connectivity exists or is in the process of being established.

Usage

From source file:com.ofalvai.bpinfo.util.Utils.java

@RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE)
public static boolean hasNetworkConnection(@NonNull Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

From source file:Main.java

/**
 * Check for 3g internet connectivity/*  ww w . j  a  va 2  s  .c  o  m*/
 *
 * @param context context
 * @return hasInternet boolean
 */
public static boolean has3gInternetAccess(@NonNull Context context) {
    try {
        boolean has3gInternet = false;
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mobile != null && mobile.isAvailable() && // !ic_mobile.isRoaming() &&
                networkInfo != null && networkInfo.isConnectedOrConnecting()) {

            has3gInternet = true;
        }

        return has3gInternet;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.hangulo.powercontact.util.Utils.java

static public boolean isNetworkAvailable(Context c) {
    ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

From source file:org.sp.attendance.utils.CodeManager.java

private static boolean checkNetwork() {
    ConnectivityManager connManager = (ConnectivityManager) ctx.getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo info = connManager.getActiveNetworkInfo();
    return (info != null && info.isConnectedOrConnecting());
}

From source file:com.mytwitter.Network.NetworkHelper.java

/**
 * Checks whether some network is connected and fully usable.
 *///  w w w  .  jav a 2s.c  o  m
public static boolean connectedToNetwork(ConnectivityManager connectivityManager) {
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    return (activeNetwork != null && activeNetwork.isConnectedOrConnecting());
}

From source file:com.mytwitter.Network.NetworkHelper.java

public static boolean connectedToNetwork(Context context) {
    ConnectivityManager connectivityManager = getConnectivityManager(context);
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    return (activeNetwork != null && activeNetwork.isConnectedOrConnecting());
}

From source file:enterprayz.megatools.Tools.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

From source file:com.mytwitter.Network.NetworkHelper.java

public static boolean connectedToWiFiOrMobileNetwork(Context context) {
    final ConnectivityManager cm = getConnectivityManager(context);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    if (!isConnected)
        return false;

    return (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            || (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE);
}

From source file:Main.java

public static boolean hasInternetAccess(Context context) {
    try {//from  w  ww .  j a  v a 2  s  .  c  o  m
        boolean hasInternet = false;

        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if ((wifi.isAvailable() || mobile.isAvailable()) && networkInfo != null
                && networkInfo.isConnectedOrConnecting()) {
            hasInternet = true;
        }

        return hasInternet;
    } catch (Exception e) {
        return false;
    }
}

From source file:codepath.watsiapp.utils.Util.java

public static Boolean isNetworkAvailable(Context activity) {
    ConnectivityManager connectivityManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    boolean isNetworkAvailable = true;
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    isNetworkAvailable = (activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting());
    return isNetworkAvailable;
}