Possible Duplicate:
how to check wifi or 3g network is available on android device
Check the Internet Connectivity in Android
I am using an Android device and I am disabling the WiFi connection in my device.Now I have an application which uses Internet and whenever the application runs I want to show a simple message i.e a Toast message telling that "No Internet connection" rather than the crashing of the application.
How to do this?
public final boolean isInternetOn()
{
ConnectivityManager connec = (ConnectivityManager) getSystemService
(Context.CONNECTIVITY_SERVICE);
if ((connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING)
||(connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED))
{
return true;
}
else
return false;
}