Android wifi信号强度与图标对应关系

扫码关注,一起学习
在这里插入图片描述
android中wifi分为5个等级,对应的图标是0格,1格,2格,3格,4格.

那么对应的信号强度是多少呢?

根据wifimanager中的算法calculateSignalLevel可以算得:

0 rssi<=-100
1 (-100, -88]
2 (-88, -77]
3 (-66, -55]
4 rssi>=-55

下面看谷歌代码实现:
/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessPointControllerImpl.java

public int getIcon(AccessPoint ap) {
    int level = ap.getLevel();
    return ICONS[level >= 0 ? level : 0];
}

frameworks/base/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java

public int getLevel() {
     return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS);
 }

关键函数:

/frameworks/base/wifi/java/android/net/wifi/WifiManager.java

private static final int MIN_RSSI = -100;

private static final int MAX_RSSI = -55;

public static final int RSSI_LEVELS = 5;


public static int calculateSignalLevel(int rssi, int numLevels) {
    if (rssi <= MIN_RSSI) {
        return 0;
    } else if (rssi >= MAX_RSSI) {
        return numLevels - 1;
    } else {
        float inputRange = (MAX_RSSI - MIN_RSSI);
        float outputRange = (numLevels - 1);
        return (int)((float)(rssi - MIN_RSSI) * outputRange / inputRange);
    }
}

你可能感兴趣的:(WIfi,Android)