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 isNetworkAvailable(Context context) {

    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();

}

From source file:Main.java

public static boolean isActiveNetworkWifi(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager != null) {
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }/*w ww  .  ja v  a  2  s  .  co m*/
    }
    return false;
}

From source file:Main.java

public static boolean isWifiConnected(Context mContext) {
    ConnectivityManager connectivityManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }/*from   ww  w .  ja  va  2s. c o  m*/
    return false;
}

From source file:Main.java

public static boolean Is3GAvailable(Context context) {
    ConnectivityManager m_NetConnectMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean bConnect = false;
    try {/*  w  ww  .j  a va  2s  .c o  m*/
        if (m_NetConnectMgr == null)
            return false;
        NetworkInfo info = m_NetConnectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        bConnect = (info.isAvailable() && info.isConnected());
    } catch (Exception e) {
        return false;
    }

    return bConnect;
}

From source file:Main.java

public static boolean isWifiNetwrokType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectivityManager.getActiveNetworkInfo();

    if (info != null && info.isAvailable()) {
        if (info.getTypeName().equalsIgnoreCase("wifi")) {
            return true;
        }//  ww  w. j  a  va  2  s .c  o m
    }
    return false;
}

From source file:Main.java

public static NetworkInfo getCurrentNetStatus(Context ctx) {
    ConnectivityManager manager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    return manager.getActiveNetworkInfo();
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean checkNetwork() {
    boolean flag = false;
    ConnectivityManager cwjManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cwjManager.getActiveNetworkInfo() != null)
        flag = cwjManager.getActiveNetworkInfo().isAvailable();
    return flag;/*from   ww w.ja  v a2  s  . co m*/
}

From source file:Main.java

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

From source file:Main.java

public static boolean isMobileDataEnable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (networkInfo == null)
        return false;

    return networkInfo.isConnectedOrConnecting();
}