'Calculating Internet Speed in android

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.



Solution 1:[1]

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.

Solution 2:[2]

This is specilally to detect internet connection speed by facebook sdk

ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();

Solution 3:[3]

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;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ovidiu Latcu
Solution 2 Lokesh Tiwari
Solution 3 Stephen Rauch