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 isWiFiOn(Context context) {
    NetworkInfo activeNetwork = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();/*from  ww  w .  j a  v  a 2 s  .c  om*/
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting()
            && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static int untetherIface(Context context, String iface) {
    int returnCode = -1;
    Object connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE);
    Method untether = null;//from w w w.jav a  2 s.  co  m
    try {
        untether = connectivityManager.getClass().getMethod("untether", new Class[] { String.class });
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        returnCode = (Integer) untether.invoke(connectivityManager, new Object[] { iface });

    } catch (Exception e) {
        e.printStackTrace();
    }
    return returnCode;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info != null && info.isConnected();
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnected()) {
        return true;
    }/*from  www. j a va2 s .c o m*/
    return false;
}

From source file:Main.java

public static boolean isMobileNetwork(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();//ww w .ja  v  a  2  s  .co  m
    return (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE);
}

From source file:Main.java

public static boolean isConnectedToWifi(Context ctx) {
    ConnectivityManager connManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return mWifi != null && mWifi.isConnected();
}

From source file:Main.java

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

From source file:Main.java

public static boolean isOnWiFi(Context context) {
    NetworkInfo activeNetwork = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();//from   ww  w .jav  a 2s. c om

    return activeNetwork != null && activeNetwork.isConnectedOrConnecting()
            && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = (cm != null) ? cm.getActiveNetworkInfo() : null;
    if (info != null && info.isAvailable() && info.isConnected()) {
        return true;
    }// www.ja v  a 2  s  . co m

    return false;
}

From source file:Main.java

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

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return (activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE);
}