Get signal strength of WIFI and Mobile Data

后端 未结 1 888
旧巷少年郎
旧巷少年郎 2020-12-05 08:19

In my app I need to check the connection speed of both WiFi and Mobile Data and then compare it, then switch to which ever network has the highest speed.

  • So ho
相关标签:
1条回答
  • 2020-12-05 08:49

    Wifi:

    WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
    int linkSpeed = wifiManager.getConnectionInfo().getRssi();
    

    In case of mobile it should work:

    TelephonyManager telephonyManager =        (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
    CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
    CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
    cellSignalStrengthGsm.getDbm();
    

    Then You should compare this signal levels and if WIFI signal is better keep it turn on, but if mobile is better disconnect wifi

    0 讨论(0)
提交回复
热议问题