Get signal strength of WIFI and Mobile Data
Asked Answered
U

1

15

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 how can I get the speed or best signal strength of wifi and mobile data?
  • how can I switch one off and other on programatically.

Please help me out. A sample would be helpful.

Unnerve answered 23/8, 2013 at 9:26 Comment(1)
Never done that before but maybe this can help you a bit mobisocial.stanford.edu/news/2011/03/… . Rest of job should be done by checking NetworkManager + connection speed tests. Hope it helpsBurnley
F
33

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

Flapdoodle answered 23/8, 2013 at 10:3 Comment(8)
how to programatically switch of wifi??Unnerve
Add premission ACCESS_WIFI_STATE, CHANGE_WIFI_STATE Then you can use the following in your activity class: wifiManager.setWifiEnabled(false);Flapdoodle
remeber that signal strength is a negative valueFlapdoodle
code for mobile signal strength checking is only applicable for and API level 17 and above.Goop
@Flapdoodle How can we determine that the connection is too low ?(I want to stop download when connection is too low in signal)Letha
However, if we use getAllCellInfo(), we must checkout location-permission, otherwise, the application will crash on android 6 and above.Disharoon
error cash android.telephony.CellInfoLte cannot be cast to android.telephony.CellInfoGsm when use 4GLymphadenitis
Remember that the GPS must be ON in order to access the mobile signal strength.Dionnadionne

© 2022 - 2024 — McMap. All rights reserved.