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:Main.java

public static boolean isDeviceConnectedToInternet(Context context) {

    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnectedOrConnecting());
}

From source file:Main.java

public static String currentNetwork(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null) {
        if (info.isAvailable() && info.isConnectedOrConnecting()) {
            String netType = info.getTypeName();
            if ("WIFI".equals(netType)) {
                return "WIFI";
            } else {
                return "2G/3G";
            }//from w w w  .ja  v  a  2  s .  c  o  m
        }
    }
    return null;
}

From source file:Main.java

/**
 * @return true if the Internet connection is available on the device, false otherwise
 *//*from   w  w w.  j ava  2 s .  c  om*/
public static boolean hasInternetConnection(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

From source file:hoahong.facebook.messenger.fbclient.MMConnector.java

public static boolean isOnline(Context activity) {
    ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }/*from   w w  w. j a va2s .c o m*/
    return false;
}

From source file:Main.java

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

From source file:com.xengar.android.englishverbs.utils.FragmentUtils.java

/**
 * Checks for internet connection.//from   ww w . j  av a2s. c o m
 * @return true if connected or connecting
 */
public static boolean checkInternetConnection(FragmentActivity fragmentActivity) {
    ConnectivityManager cm = (ConnectivityManager) fragmentActivity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return (activeNetwork != null && activeNetwork.isConnectedOrConnecting());
}

From source file:Main.java

/**
 * Method to check weather the network is available in the device
 * //from   w  ww.  j a va2 s . c  om
 * @param context
 * @return
 */
private static boolean isConnectionAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();

    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

From source file:Main.java

public static boolean isConnectionToWifi(Context applicationContext) {
    ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
        return true;
    }/* w w w .  j av a2  s. co  m*/
    return false;
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cManager != null) {
        NetworkInfo localNetworkInfo = cManager.getActiveNetworkInfo();
        if (localNetworkInfo != null) {
            return localNetworkInfo.isConnectedOrConnecting();
        }// ww  w .  j av  a2s .  c  o m
    }
    return false;
}

From source file:Main.java

public static Map<String, String> getNetworkInfo(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    Map<String, String> map = new HashMap();
    NetworkInfo info = cm.getActiveNetworkInfo();
    if ((info == null) || (!info.isConnectedOrConnecting()) || (withinInBlackList())) {
        map.put("access_subtype", "offline");
        map.put("access", "offline");
        map.put("carrier", "");
    } else {/*from   w w  w  .  j  a  v  a2 s  . c  o m*/
        map.put("access_subtype", info.getSubtypeName());
        map.put("access", cleanNetworkTypeName(info.getTypeName()));
        TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        String carrierName = manager.getNetworkOperatorName();
        map.put("carrier", carrierName);
    }
    return map;
}