How to check internet connection is active/inactive while wifi is enabled in android
I am making an android application. In this applicati开发者_运维百科on i am receiving data from server. When Wi-Fi is enabled and internet connection is active in our device then it returns the number of record from the server but whenever wifi is enabled but inernet connection is not active or inactive then it gives the force close. I have already checked the wifi connection is enabled.
Please tell me this how can i check that internet is active in our device.
Thanks for advance
Try this code
private boolean isNetworkAvailable()
{
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
精彩评论