Getting data speed of wifi/mobile network programm

2019-01-13 22:28发布

问题:

This question already has an answer here:

  • How to get link speed programmatically? 3 answers

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

回答1:

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