Calculating Internet Speed in android

前端 未结 4 643
遥遥无期
遥遥无期 2020-12-08 22:32

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

4条回答
  •  囚心锁ツ
    2020-12-08 23:03

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

    WifiManager wifiManager = (WifiManager) 
        this.getSystemService(Context.WIFI_SERVICE);
    
    List 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;
    }
    

提交回复
热议问题