This code always returns true. This is called up when the "Login" button is clicked. At first I tried to connect to Wi-Fi (on the emulator). It came back and then I turned off Wi-Fi and then tried. it returns true anyway.
public static boolean isNetworkAvailable( Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); // if no network is available networkInfo will be null // otherwise check if we are connected if (networkInfo != null && networkInfo.isConnected()) { State network = networkInfo.getState(); Log.d("here", "true"); return (network == NetworkInfo.State.CONNECTED || network == NetworkInfo.State.CONNECTING); } Log.d("here1", "false"); return false; }
, - . , , , , , -. , 3G, Wi-Fi . , "", .
, , - , . () . , , , .