Getting WiFi signal strength in Android

别来无恙 提交于 2019-11-27 06:53:07
Alan

its an old post but this might help someone...

WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int numberOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);

Documentation: public static int calculateSignalLevel (int rssi, int numLevels)

Please check how dBm values for received Wireless Signal power are represented.

Excellent >-50 dBm

Good -50 to -60 dBm

Fair -60 to -70 dBm

Weak < -70 dBm

ddiego
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

// Level of a Scan Result
List<ScanResult> wifiList = wifiManager.getScanResults();
for (ScanResult scanResult : wifiList) {
  int level = WifiManager.calculateSignalLevel(scanResult.level, 5);
  System.out.println("Level is " + level + " out of 5");
}

// Level of current connection
int rssi = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 5);
System.out.println("Level is " + level + " out of 5");

Yes, exactly. This is how dBm values for received signal power are represented. Here are some details at Wikipedia.

-100 means lowest value (no signal at all), and 0 means extremely good signal (100%)

You already have got the levels, So i will tell you how to classify that wifi into high,medium or low strength. Following is the code

int level = result.level;

    if (level <= 0 && level >= -50) {
        //Best signal

    } else if (level < -50 && level >= -70) {
        //Good signal


    } else if (level < -70 && level >= -80) {
        //Low signal


    } else if (level < -80 && level >= -100) {
       //Very weak signal

    } else {
       // no signals
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!