5

I have to show a page if network connection is slow

iam checking the network by using this code

   ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info.getType() == ConnectivityManager.TYPE_WIFI) {
        Toast.makeText(MainActivity.this,"wifi",Toast.LENGTH_LONG).show();


        // do something
    } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {


        // check NetworkInfo subtype
        if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_GPRS) {
            Toast.makeText(MainActivity.this,"mobile 100kbps",Toast.LENGTH_LONG).show();
            // Bandwidth between 100 kbps and below
        } else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EDGE) {
            Toast.makeText(MainActivity.this,"mobile 50-100kbps",Toast.LENGTH_LONG).show();

            // Bandwidth between 50-100 kbps
        } else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EVDO_0) {
            Toast.makeText(MainActivity.this,"mobile 400-1000kbps",Toast.LENGTH_LONG).show();

            // Bandwidth between 400-1000 kbps
        } else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EVDO_A) {
            Toast.makeText(MainActivity.this,"mobile 600-1400kbps",Toast.LENGTH_LONG).show();

            // Bandwidth between 600-1400 kbps
        }

it is showing the wifi network But i need the code for slow wifi network. Please help me is there any code to check slow wifi network.

Lassie
  • 984
  • 11
  • 25
  • 1
    use [network connection class](https://github.com/facebook/network-connection-class) by facebook. – shinilms Jun 13 '17 at 10:10

2 Answers2

2

Use below method to check the wifi level:

public int getWifiLevel()
{
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int linkSpeed = wifiManager.getConnectionInfo().getRssi();
    int level = WifiManager.calculateSignalLevel(linkSpeed, 5);
    return level;
}

Based on wifi level or link speed you can decide if it has the low connection or high connection internet.

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
Chirag
  • 56,621
  • 29
  • 151
  • 198
1

You can use following code for checking wifi speed

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

I hope this may helps you.

Shreeya Chhatrala
  • 1,441
  • 18
  • 33