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 verifyConnection(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnected()) {
        return true;
    } else {//from   w ww .  j a  v a2  s  .  c  o  m
        return false;
    }
}

From source file:Main.java

public static boolean isConnect(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    } else {//from  w  w w  .  j a va2 s.co m
        return false;
    }
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();//ww  w.j  av  a  2  s . c  o m
    return networkInfo != null && networkInfo.isConnected();
}

From source file:Main.java

public static Boolean isNetworkReachable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo current = cm.getActiveNetworkInfo();
    if (current == null) {
        return false;
    }/*from w  ww .ja  v a2 s  .  co m*/
    return (current.isAvailable());
}

From source file:Main.java

public static boolean isWifi(Context context) {
    ConnectivityManager con = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    State wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (wifi == State.CONNECTED)
        return true;
    else//from   w w w .j a v  a  2s .com
        return false;
}

From source file:Main.java

public static boolean isNetWorkdetect(Context context) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkinfo = conn.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }//from  ww w . j a v  a  2s  .co  m
    return true;
}

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  ww  w.j  a v  a2s . c  om
        }
    }
    return null;
}

From source file:Main.java

public static boolean hasNetwork(Context context) {
    ConnectivityManager con = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo workinfo = con.getActiveNetworkInfo();
    if (workinfo == null || !workinfo.isAvailable()) {
        return false;
    } else {/*from   w  ww  . j a  va2 s.c o  m*/
        return true;
    }
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni == null) {
        // There are no active networks.
        return false;
    } else//www  .  ja  v a 2s.  c om
        return true;
}

From source file:Main.java

public static boolean isNetworkReachable(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();/*from w  w w  .  j a  v a 2s  . c o  m*/
    if (networkInfo != null) {
        return networkInfo.isAvailable();
    }
    return false;
}