Hi Friends, if you like my blog please give your valuable comments it will help to improve my blog content and enthusiasm to write a lot in android World.

Wednesday, November 21, 2012

check internet is available?

This function will return true if you can access the internet (or false if you can't). You can change the parameter being return when roaming 


/*
* @return boolean return true if the application can access the internet
*/
private boolean haveInternet(){
NetworkInfo info = ((ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info==null || !info.isConnected()) {
return false;
}
if (info.isRoaming()) {
// here is the roaming option you can change it if you want to disable internet while roaming, just return false
return true;
}
return true;
}

No comments:

Post a Comment