15

How do I get the data speed of wifi/mobile network programmatically in my application.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ullas
  • 383
  • 2
  • 6
  • 13
  • 3
    Try opening a socket and download some bytes from somewhere (say 256kb) and measure how long it takes for the download to complete – Ziv Kesten Dec 24 '15 at 15:23
  • 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:25

1 Answers1

19

Here's the code for getting the WiFi speed:

WifiManager wifiManager = getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
    Integer linkSpeed = wifiInfo.getLinkSpeed(); //measured using WifiInfo.LINK_SPEED_UNITS
}

For mobile network speed, refer to the below link:

http://www.gregbugaj.com/?p=47

Hariharan
  • 24,741
  • 6
  • 50
  • 54