Android开发之WiFi模块

Android-WiFi开发之 WiFi信号强度

2017-06-23  本文已影响375人  迷你小猪

RSSI 小知识:

  1. 全称: Received Signal Strength Indication.
  2. 含义: 接收的信号强度指示,无线发送层的可选部分,用来判定链接质量,以及是否增大广播发送强度。
  3. WIFI RSSI, 开发中单纯表示信号强度. WIFI 列表排序中, 其也会占一席之地.
  4. WIFI 中的 RSSI, 官方文档中定义了两个值, 分别是: MIN_RSSI = -100, MAX_RSSI = -55;

WIFI RSSI 小知识:

  1. private static final int MIN_RSSI = -100. 表示最弱程度的WIFI信号强度.
  2. private static final int MAX_RSSI = -55. 表示最强程度的WIFI信号强度.
  3. 当前WiFi很弱的情况, 如果当前获取的WiFi-ap的rssi的值比此值还要小, 或者相等, 那么当前可以显示0等级;
  4. 当前WiFi很强的情况, 如果当前获取的WiFi-ap的rssi的值比此值还要大, 或者相等, 那么当前可以显示最高等级;

根据 RSSI 计算 WIFI 等级:

    public static final String RSSI_CHANGED_ACTION = "android.net.wifi.RSSI_CHANGED";
    // 获取 WIFI 等级, levelMax 为你想取得的最高等级, 大于0, 通常人会使用3, 4, 5.
    public static int getWifiLevelByRssi(WifiManager manager, int rssi, int levelMax) {
        if (levelMax <= 0) {
            throw new IlleagalArgumentException("param levelMax must much more then 0");
        }
        if (manager == null) {
            throw new IlleagalArgumentException("param levelMax must not be null);
        }
        return manager.calculateSignalLevel(rssi, levelMax);
    }
    如果, 当前WiFi-ap的rssi是<=-100, 那么, 计算后, 返回0;
    如果, 当前WiFi-ap的rssi是>=-55, 那么, 计算后, 返回4;
    其他的范围, 按照: (rssi-(-100))*4/(-55-(-100)), 也就是: 4*(rssi+100)/45.
上一篇 下一篇

猜你喜欢

热点阅读