Example usage for android.net ConnectivityManager getNetworkInfo

List of usage examples for android.net ConnectivityManager getNetworkInfo

Introduction

In this page you can find the example usage for android.net ConnectivityManager getNetworkInfo.

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getNetworkInfo(@Nullable Network network) 

Source Link

Document

Returns connection status information about a particular Network.

Usage

From source file:Main.java

public static boolean isConnectedWiFi(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
}

From source file:Main.java

public static String getApn(final Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS).getExtraInfo();
}

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  ww  w. j a v  a  2s  .co  m
        return false;
}

From source file:Main.java

public static boolean checkConn(Context ctx) {
    ConnectivityManager conMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (conMgr.getNetworkInfo(conMgr.TYPE_MOBILE).isConnectedOrConnecting()
            || conMgr.getNetworkInfo(conMgr.TYPE_WIFI).isConnectedOrConnecting()) {
        Log.v(TAG, "Able to connect to the network");
        return true;
    } else {//from   w  ww.  j a v a2s  .c o  m
        Log.e(TAG, "Unable to connect to network");
    }
    return false;
}

From source file:Main.java

public static boolean isWifiOnline(Context context) {
    ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();

    return wifi == State.CONNECTED;
}

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 isWIFIConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return info != null && info.isConnected();
}

From source file:Main.java

public static boolean isMobileOnline(Context context) {
    ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();

    return mobile == State.CONNECTED;
}

From source file:Main.java

public static boolean checkEthernet(Context context) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = conn.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
    return networkInfo.isConnected();
}

From source file:Main.java

public static boolean checkStatusWifi(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifi != null) {
        return wifi.isConnected();
    } else/*from  ww w.  ja v a2 s  . c  o m*/
        return false;
}