when wifi is connected to wireless modem internet coverage is there or not it always says yes you are conected it only checks wifi conectivity not internet connectivity so how to handle such a situation ?
Tap Settings > Wireless & Networks > Wi-Fi as shown in Figure 1. If Wi-Fi is off, tap the slider to turn Wi-Fi on. When Wi-Fi is on, a signal indicator appears at the top right corner of your home screen.
Go to Start , select Settings > Network & Internet, and see whether your wireless network name appears in the list of available networks. If you see your wireless network name, select it and select Connect.
In your advanced Wi-Fi settings, select Manage networks. This is usually found beneath Network Settings. Now you'll see a list of all the Wi-Fi networks currently saved on your phone. To delete specific networks, tap them and select Forget.
1.)u can check it as
URL url = new URL("YOUR urlString");
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
.
.
int responseCode = conn.getResponseCode();
//if responseCode = 200 - THEn CONN is connected
OR
2.) u can do somethin like dis
public static boolean isNetworkAvailable(Activity activity) {
ConnectivityManager connectivity = (ConnectivityManager) activity
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true; //<-- -- -- Connected
}
}
}
}
return false; //<-- -- -- NOT Connected
}
Try this.
private boolean haveNetworkConnection(Context context)
{
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo)
{
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
{
if (ni.isConnected())
{
haveConnectedWifi = true;
Log.v("WIFI CONNECTION ", "AVAILABLE");
} else
{
Log.v("WIFI CONNECTION ", "NOT AVAILABLE");
}
}
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
{
if (ni.isConnected())
{
haveConnectedMobile = true;
Log.v("MOBILE INTERNET CONNECTION ", "AVAILABLE");
} else
{
Log.v("MOBILE INTERNET CONNECTION ", "NOT AVAILABLE");
}
}
}
return haveConnectedWifi || haveConnectedMobile;
}
Hope it will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With