Hi all,
I want to check the network connectivity in android application.so i inserted the following code
public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
{
for (int i = 0; i < info.length; i++)
{
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
}
}
return false;
}
when i removed network cable in my computer the program crashed.but when i disable Airplane Mode in Emulator,it correctly shows "NETWORK NOT AVAILABLE". How to we actually check?