I'm trying to check the network status in my android application.
And I have code like this:
public boolean isNetworkAvailable()
{
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if(networkInfo != null && networkInfo.isConnected())
return true;
return false;
}
This code is returning true
when network is available as expected but it is also returing true
even in case of network not-available.
Simply put its returning true
for both the cases!
Where I'm making the mistake in the code?
Note that I run the app in my emulator.
Thanks in advance.