Example usage for android.content Context CONNECTIVITY_SERVICE

List of usage examples for android.content Context CONNECTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context CONNECTIVITY_SERVICE.

Prototype

String CONNECTIVITY_SERVICE

To view the source code for android.content Context CONNECTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.net.ConnectivityManager for handling management of network connections.

Usage

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    boolean availability = false;
    try {/*from ww w  . j  a v  a  2s.  c o m*/
        if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED
                || conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                        .getState() == NetworkInfo.State.CONNECTED) {
            availability = true;
        }
    } catch (Exception e) {
        return true;
    }
    return availability;
}

From source file:Main.java

public static boolean isWIFI(Context context) {
    try {/* w  w w  .j a  va 2s . com*/
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm != null) {
            NetworkInfo ni = cm.getActiveNetworkInfo();
            if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) {
                return true;
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}

From source file:Main.java

public static boolean checkNetwork(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = connectivity.getActiveNetworkInfo();
    return (activeNetwork != null && activeNetwork.isConnected());
}

From source file:Main.java

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

From source file:Main.java

public static int getNetWorkType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo();
    return networkInfo == null ? -1 : networkInfo.getType();
}

From source file:Main.java

public static boolean isNetWorkInfoNull(Context context) {
    ConnectivityManager conManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = conManager.getActiveNetworkInfo();
    return networkInfo == null ? true : false;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isOnWifiInternet(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    return (info.isAvailable() && info.isConnected());
}

From source file:Main.java

public static boolean isEthernetDataEnable(Context context) throws Exception {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isEthernetDataEnable = false;

    isEthernetDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET)
            .isConnectedOrConnecting();/*from   ww w . j  a  v a 2  s.c  om*/

    return isEthernetDataEnable;
}

From source file:Main.java

public static boolean isOnWIFI(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnectedOrConnecting() && ni.getType() == ConnectivityManager.TYPE_WIFI;
}