Getting WiFi signal strength in Android

AndroidAndroid Wifi

Android Problem Overview


I can get WiFi signal level in dBm using following code.

for (ScanResult result : wifiScanResultList) {
	int signalLevel = result.level;
}

It gives negative value. When we see the default system WiFi setting and clicked on the connected WiFi network, it gives "Good" or "Bad" as signal strength. What is the range that we can filter those negative vales as "Good" signal strength or "Bad" signal strength?

Android Solutions


Solution 1 - Android

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)

Solution 2 - Android

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

Solution 3 - Android

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");

Solution 4 - Android

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%)

Solution 5 - Android

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

    int level = result.level;

    if (level >= -50) {
        //Best signal
    } else if (level >= -70) {
        //Good signal         
    } else if (level >= -80) {
        //Low signal
    } else if (level >= -100) {
       //Very weak signal
    } else {
       //Too low signal
    }

Solution 6 - Android

Here are the wifi signal levels used by the Samsung A7 :

return when (rssi) {
    in -63..-1 -> 4
    in -73..-64 -> 3
    in -83..-74 -> 2
    in -93..-84 -> 1
    else -> 0
}

I think it should be pretty similar for the other brands.

Solution 7 - Android

The Constants from WifiManager.java are slightly different so I will add them here:

MIN_RSSI: Anything worse than or equal to -100 will show 0 bars.

MAX_RSSI: Anything better than or equal to -55 will show the max bars.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnujAroshAView Question on Stackoverflow
Solution 1 - AndroidAlanView Answer on Stackoverflow
Solution 2 - AndroidNisha SalimView Answer on Stackoverflow
Solution 3 - AndroidddiegoView Answer on Stackoverflow
Solution 4 - AndroidOleksandr KravchukView Answer on Stackoverflow
Solution 5 - AndroidAjjiView Answer on Stackoverflow
Solution 6 - AndroidDenisView Answer on Stackoverflow
Solution 7 - AndroideinUsernameView Answer on Stackoverflow