List of usage examples for android.net NetworkInfo.State equals
public boolean equals(Object obj)
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)); }