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:org.proninyaroslav.libretorrent.core.utils.Utils.java

public static boolean checkNetworkConnection(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

    return activeNetwork.isConnectedOrConnecting();
}

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

public static boolean connectedToWiFiNetwork(ConnectivityManager connectivityManager) {
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    if (!isConnected)
        return false;

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

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

public static boolean connectedToMobileNetwork(ConnectivityManager connectivityManager) {
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    if (!isConnected)
        return false;

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

From source file:com.asalfo.wiulgi.util.Utils.java

/**
 * Returns true if the network is available or about to become available.
 *
 * @param c Context used to get the ConnectivityManager
 * @return true if the network is available
 *//*from  ww  w.j  a va 2 s . c om*/
static public boolean isNetworkAvailable(@NonNull Context c) {
    ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);

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

From source file:Main.java

/**
 * Checks for internet access/*  ww w .j a v a 2s . c  o  m*/
 *
 * @param context context
 * @return hasInternet boolean
 */
public static boolean hasInternetAccess(@NonNull Context context) {
    try {
        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:jahirfiquitiva.iconshowcase.utilities.utils.Utils.java

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

From source file:com.sinpo.xnfc.nfc.Util.java

/**
 * ??/*from  w  ww.  jav  a  2 s .  c  om*/
 * @return
 */
public static boolean isNetworkConnected(Context c) {
    ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnectedOrConnecting();
}

From source file:org.restcomm.app.utillib.Utils.Global.java

public static boolean isOnline(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connectivityManager != null) {
        NetworkInfo netinfo = connectivityManager.getActiveNetworkInfo();
        if (netinfo != null)
            return netinfo.isConnectedOrConnecting();
    }//from w  w w .  j a v a  2  s .  c  o m
    return false;
}

From source file:org.arasthel.almeribus.utils.LoadFromWeb.java

public static boolean isConnectionEnabled(Context context) {
    boolean connected = false;
    if (context != null) {
        ConnectivityManager conManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] infos = conManager.getAllNetworkInfo();
        for (NetworkInfo netInfo : infos) {
            if (netInfo.isConnectedOrConnecting()) {
                connected = true;//from  w  w w  .j  a v a 2  s .c  o  m
            }
        }
    }
    return connected;
}

From source file:com.yelinaung.android.utils.NetUtils.java

public static boolean isOnlineOrNot(Context c) {
    NetworkInfo netInfo = null;
    try {/*ww  w .ja va 2  s.c  o  m*/
        ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
        netInfo = cm.getActiveNetworkInfo();
    } catch (SecurityException e) {
        e.printStackTrace();
    }
    return netInfo != null && netInfo.isConnectedOrConnecting();
}