In a android studio project I want to check active internet, for that I use this class. Its working but. problem is it only work when connection not available. But i want only return true when connection is active and workable. Because the app working with webview, and if connection is week or not active then its showing not reachable error. Its happening most with WiFi. Please help
public boolean isConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netinfo = cm.getActiveNetworkInfo();
if (netinfo != null && netinfo.isConnectedOrConnecting()) {
android.net.NetworkInfo wifi =
cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile =
cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if((mobile != null && mobile.isConnectedOrConnecting()) || (wifi != null &&
wifi.isConnectedOrConnecting()))
{
return true;
}
else {
return false;
}
} else{
return false;
}
}