Calculating Internet Speed in android
Asked Answered
M

3

17

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.

Mcvay answered 3/8, 2012 at 13:6 Comment(2)
this may help #4430105Trisect
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?Arette
D
12

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.

Dermott answered 3/8, 2012 at 13:37 Comment(6)
Any way thank you, but still i am searching for internet speed not only in wifi as well as in 3G,2G.Mcvay
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 routerAttorney
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.Layfield
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???Gamages
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?Arette
network link speed != internet speedEbbie
B
0

This is specilally to detect internet connection speed by facebook sdk

ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();
Beatty answered 1/11, 2015 at 10:10 Comment(3)
It's Always returns UNKNOWN.Sesterce
This Always returns unknownStaffard
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.Paraphrase
S
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;
}
Silencer answered 7/10, 2017 at 4:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.