Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow internet connection issue in android

I'm creating an application in Android in which checks the Internet connectivity. I want to display a toast message when the Internet connection is very slow. Or when the server does not respond to a request. In this case I want to put a toast like Connection is slow !!!. Here in my code I have found the whether the internet is connected or not, but don't know how to toast the message of internet slow...

public boolean isConnectingToInternet(){
    ConnectivityManager connectivity = (ConnectivityManager) _context.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)
                  {
                      return true;
                  }

      }
      return false;
}
like image 311
Hitesh Kamani Avatar asked Mar 29 '13 13:03

Hitesh Kamani


People also ask

Why is my internet slow on my Android phone?

Why is the internet so slow on my phone? A slow data connection on your phone is usually caused by a poor connection in your location, network congestion, or too many background apps running.

Why is my phone internet all of a sudden slow?

The main reason phones slow down over time is because new operating updates leave older phones behind. Likewise, internet browsing apps update to sync with newer, better phones. If you don't have the latest and greatest, your phone could struggle with the newest operating system and app updates.


1 Answers

  • For WiFi link speed check WifiInfo.getLinkSpeed()
  • For Mobile Data Link you can only check TelefonyManager.getNetworkType() to determine the current Mobile Data Link type. You should then aproximate to actual speed by link type (i.e. for GPRS up to 128 kbps, for EDGE up to 236.8 kpbs, for 3G up to 2 Mbps, for HDSPA up to 7.2 Mbps). Take into consideration that this is only an aproximation. Your could be conneting using HDSPA but your carrier limiting the top speed to 2 Mbps.

Now , you have to get speed and put condition whether below 100kbps , "low internet connection"

like image 185
Nirav Ranpara Avatar answered Sep 28 '22 03:09

Nirav Ranpara