1

In my apps i use some Network Available check but problem is when internet connected but no Internet speed then destroy my apps. Normal method return only internet connected or not but when signal in low then it's now working .

Md Imran Choudhury
  • 9,343
  • 4
  • 62
  • 60
  • Yes i know duplicate question but i found a problem when wifi is connected but no internet available in wifi router then not work in samsung phone. then i post this and also write e comment . – Md Imran Choudhury Apr 15 '15 at 07:41

1 Answers1

0

I use this method to solve this problem.

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

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Md Imran Choudhury
  • 9,343
  • 4
  • 62
  • 60