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 isInternetConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }/* ww  w .  jav a2s  .  com*/
    return true;
}

From source file:Main.java

public static boolean netIsEnable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info == null) {
        return false;
    } else {/*  w w w  . j  av  a  2s.  c om*/
        if (info.isAvailable()) {
            return true;
        } else {
            return false;
        }
    }
}

From source file:Main.java

public static boolean isMobileConnected(Context context) {
    ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (mgr == null)
        return false;
    NetworkInfo info = mgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (info == null)
        return false;
    NetworkInfo.State state = info.getState();
    return state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cManager.getActiveNetworkInfo();
    if (info != null && info.isAvailable()) {
        return true;
    } else {//from  w  ww.  ja va2 s .  c o m
        return false;
    }
}

From source file:Main.java

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

    if (null == cm) {
        return false;
    }//from w  w w  . ja v  a  2 s .  c  o  m

    NetworkInfo info = cm.getActiveNetworkInfo();
    if (null != info) {
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;

}

From source file:Main.java

private static boolean isWIFIConnection(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfo != null) {
        return networkInfo.isConnected();
    }//from  www  .j  av a  2s  .c  om
    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();
        }/*from   ww w  .  j  a  va  2s  . c  om*/
    }
    return false;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = null;/*from   ww w. j a  v a2  s  . co m*/
    if (manager != null)
        networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo == null)
        return false;
    if (networkInfo.isConnected())
        return true;
    return false;
}

From source file:Main.java

public static boolean checkInternetConnection(Context context) {

    ConnectivityManager con_manager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (con_manager.getActiveNetworkInfo() != null && con_manager.getActiveNetworkInfo().isAvailable()
            && con_manager.getActiveNetworkInfo().isConnected()) {
        return true;
    } else {/*from   ww w  .j  av a  2 s. c  o m*/
        return false;
    }
}