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 isOnline(Activity activity) {
    ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isWIFI(Context cxt) {
    ConnectivityManager connectivityManager = (ConnectivityManager) cxt
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }/* w  ww . ja v  a2  s . co m*/
    return false;
}

From source file:Main.java

public static boolean checkNetWork(Context context) {
    boolean flag = false;
    ConnectivityManager cwjManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cwjManager.getActiveNetworkInfo() != null)
        flag = cwjManager.getActiveNetworkInfo().isAvailable();
    return flag;// w  ww  . j av  a 2 s.c o m
}

From source file:Main.java

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

    }
    return false;
}

From source file:Main.java

protected static int getMoblieNetType(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectMgr.getActiveNetworkInfo();
    return info.getSubtype();
}

From source file:Main.java

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

    return mWifi.isConnected();
}

From source file:Main.java

public static boolean checkConnection(Context context, boolean onlyWiFi) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    boolean isWiFi = activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
    if (!onlyWiFi) {
        return isConnected;
    } else {/* w  ww.  j av  a 2s.  co  m*/
        return isConnected && isWiFi;
    }
}

From source file:Main.java

public static boolean has(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
        return false;
    }/*from  w  w w. j  a  v a 2 s  . co m*/
    NetworkInfo info = connectivityManager.getActiveNetworkInfo();
    return (info != null) && info.isAvailable();
}

From source file:Main.java

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

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    try {/*from  w w w  .ja va 2 s .c  om*/
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        return null != info && info.isConnected();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}