Example usage for android.net NetworkInfo.State equals

List of usage examples for android.net NetworkInfo.State equals

Introduction

In this page you can find the example usage for android.net NetworkInfo.State equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:Main.java

static public boolean isDisconnectedIntent(Intent intent) {
    boolean res = false;
    NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
    if (networkInfo != null) {
        NetworkInfo.State state = networkInfo.getState();
        res = (state.equals(NetworkInfo.State.DISCONNECTING) || state.equals(NetworkInfo.State.DISCONNECTED))
                && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI);

    } else {/*  ww w  .j a v a  2 s  . c om*/
        int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
        if (wifiState == WifiManager.WIFI_STATE_DISABLED || wifiState == WifiManager.WIFI_STATE_DISABLING) {
            res = true;
        }
    }
    return res;
}

From source file:Main.java

public static boolean isMobileConnection(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo.State mobile = null;

    if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null) {
        mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    }/*from  w w  w  . j  a v  a2s  . c o  m*/

    return (mobile != null && mobile.equals(NetworkInfo.State.CONNECTED));
}