Check Network Available in android with internet data speed.
public boolean isConnectingToInternet(){
ConnectivityManager connectivity = (ConnectivityManager) Login_Page.this.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
try
{
HttpURLConnection urlc = (HttpURLConnection) (new URL("http://www.google.com").openConnection());
urlc.setRequestProperty("User-Agent", "Test");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(500); //choose your own timeframe
urlc.setReadTimeout(500); //choose your own timeframe
urlc.connect();
int networkcode2 = urlc.getResponseCode();
return (urlc.getResponseCode() == 200);
} catch (IOException e)
{
return (false); //connectivity exists, but no internet.
}
}
}
return false;
}
This Function return true or false.
Must get user permission