I have facing a problem regarding device is available on internet or not.Let me explain my query in brief with a example: I have test my application with a use case i.e I have on my router wifi but I unplug the Ethernet cable from my router and connect my device on wifi and by using following code:
private boolean checkConnection() {
boolean connected = false;
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if ((ni.getTypeName().equalsIgnoreCase("WIFI")
|| ni.getTypeName().equalsIgnoreCase("MOBILE"))
& ni.isConnected() & ni.isAvailable()) {
connected = true;
}
}
}
return connected;
}
I will get a Boolean flag for connectivity .This code return the device status of switch means my device is connected with WiFi or not but I will not getting any response from the server or host,So I need to check the internet feasibility on my device or not .Please some one help me for the same.I have tried many goggling approaches or methodology but failed in success.
Thanks in advance.
If you need to check if connection actually provides internet, you can try pinging some remote host - google, for example: How to Ping External IP from Java Android