I'm able to detect Internet connection using
public class InternetDetector {
private Context _context;
public InternetDetector(Context context) {
this._context = context;
}
/**
* Checking for all possible internet providers
**/
public Boolean isConnectingToInternet() {
ConnectivityManager connectivityManager
= (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}
public Boolean isOnline() {
try {
Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com");
int returnVal = p1.waitFor();
boolean reachable = (returnVal == 0);
return reachable;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
}
This works perfectly if there is internet, but in some cases I am able to connect to WIFI but no internet. In this case If internet is not available I nned to show a message[No INTERNET CHECK YOUR CONNECTION] to user after 10 seconds
How can I achieve it.