16

I am working with an App which contains web service things.

In that I need to know the status when the Internet speed is low. How to find the internet speed level in Android?

For example, Consider if I am using 2Mbps connection in my cell phone and when it slows to 50Kbps I need to notice that situation by making a Toast or Alert.

Thanks.

Hesham Saeed
  • 5,358
  • 7
  • 37
  • 57
Dhamodharan
  • 195
  • 1
  • 2
  • 20
  • this may help http://stackoverflow.com/questions/4429605/how-to-get-link-speed-programmatically – Calvin Sep 20 '12 at 07:57
  • So what did you find? I want to check internet speed and set image or video url accordingly for example if internet speed is between `50kbps - 150 kbps` **link1** , `150kbps - 500kbps` **link2** and `>500kbps` **link3**. so How to achieve that? – Bhavin Patel Jun 01 '21 at 06:26

3 Answers3

11

If you are connected to WiFi you can find the speed of the connection using WifiManager :

WifiInfo wifiInfo = wifiManger.getConnectionInfo();

and then from the WifiInfo you can get the current speed :

int speedMbps = wifiInfo.getLinkSpeed();

If you are on 3G, I don't think there is a standard way of finding out, maybe you can assume automatically that 3G is slow.

Ovidiu Latcu
  • 71,607
  • 15
  • 76
  • 84
  • 2
    Any way thank you, but still i am searching for internet speed not only in wifi as well as in 3G,2G. – Dhamodharan Aug 03 '12 at 13:42
  • 4
    This answer is incorrect, it's not possible to get your Internet speed like this since it's determined by your ISP, not your WiFi adapter or router – mittelmania Dec 27 '14 at 08:56
  • There is no `android library` that provides the speed of the network. `wifiInfo.getLinkSpeed` provides the maximum speed of the network only which keeps on changing time to time. – the_unknown_spirit Jul 04 '16 at 12:25
  • if user's are connected using Mobile data than which method is used to find out Speed of internet connection, please let me know if any one find out correct solution??? – Sanjay Bhalani Sep 13 '16 at 06:18
  • I want to check internet speed and set image or video url accordingly for example if current internet speed is between `50kbps - 150 kbps` **link1** , `150kbps - 500kbps` **link2** and `>500kbps` **link3**. so How to achieve that? – Bhavin Patel Jun 01 '21 at 06:26
0

This is specilally to detect internet connection speed by facebook sdk

ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();
Lokesh Tiwari
  • 10,496
  • 3
  • 36
  • 45
  • 1
    It's Always returns UNKNOWN. – Ronak Gadhia May 02 '17 at 12:47
  • This Always returns unknown – surya Oct 24 '17 at 10:42
  • it always returns null because there was no network sampling done before fetching the value from network bucket, for this to work you need to start the sampling and download a dummy image from a server and then stop sampling. After that, you can get values from network bucket. – Swapnil Kadam Feb 07 '18 at 07:36
0

This is the code for getting speed of your internet while connected to wifi.

WifiManager wifiManager = (WifiManager) 
    this.getSystemService(Context.WIFI_SERVICE);

List<ScanResult> wifiList = wifiManager.getScanResults();
for (ScanResult scanResult : wifiList) {
    int level = WifiManager.calculateSignalLevel(scanResult.level, 5);
    String net=String.valueOf(level);
   // Toast.makeText(MainActivity.this,net,Toast.LENGTH_LONG).show();

}

// Level of current connection.here rssi is the value of internet speed whose value
// can be -50,-60 and some others,you can find the speed values easily on internet.

int rssi = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 5);
String net=String.valueOf(rssi);
Toast.makeText(MainActivity.this,net,Toast.LENGTH_LONG).show();

// -100 is the minimum speed value of your internet.
if(rssi < -100) {
    slowInternet=false;
}
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135