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 isNetworkConnected(Context context) {
    boolean resp = false;
    final ConnectivityManager connMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connMgr.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.isAvailable()) {
        resp = true;/*from   www. ja va2 s .co  m*/
    }
    return resp;
}

From source file:Main.java

public static boolean checkNetworkStatus(Context context) {
    boolean resp = false;
    final ConnectivityManager connMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connMgr.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.isAvailable()) {
        resp = true;// w w w  . j a  v  a  2 s  .  co m
    }
    return resp;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo[] netInfo = cm.getAllNetworkInfo();

    for (NetworkInfo ni : netInfo) {
        String name = ni.getTypeName();

        if (name.equalsIgnoreCase("ETH"))
            if (ni.isConnected())
                return true;

        if (name.equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                return true;

        if (name.equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                return true;
    }//from ww w . ja  va2 s  .  c o m

    return false;
}

From source file:Main.java

public static Boolean NetWorkIsWifi(Context mContext) {
    boolean netStatus = false;
    ConnectivityManager connManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi.isConnected()) {
        netStatus = true;//from   w  w w . j a va  2 s. c  om

    }
    return netStatus;

}

From source file:Main.java

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

From source file:Main.java

public static boolean isNetWorkAvailable(Context context) {
    boolean bisConnFlag = false;
    ConnectivityManager conManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo network = conManager.getActiveNetworkInfo();
    if (network != null) {
        bisConnFlag = network.isAvailable();
    }/*  ww  w .  j av  a 2  s.c om*/
    return bisConnFlag;
}

From source file:Main.java

public static boolean checkNet(Activity act) {
    ConnectivityManager manager = (ConnectivityManager) act.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }// w  w  w  .  j  a v  a 2s .co m
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }
    return true;
}

From source file:Main.java

public static boolean isNetDeviceAvailable(Context context) {
    boolean bisConnFlag = false;
    ConnectivityManager conManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo network = conManager.getActiveNetworkInfo();
    if (network != null) {
        bisConnFlag = conManager.getActiveNetworkInfo().isAvailable();
    }/*from w  w  w  .ja  va 2s  .c o m*/
    return bisConnFlag;
}

From source file:Main.java

public static boolean isNetworkAvaliable(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connManager.getActiveNetworkInfo();
    return ((netInfo != null) && netInfo.isConnected());
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    try {//from w w  w .  j  a  v a2  s  . c  o m
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo info = connectivity.getActiveNetworkInfo();
            if (info != null && info.isConnected()) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}