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.

Renjith
  • 5,783
  • 9
  • 31
  • 42
WISHY
  • 11,067
  • 25
  • 105
  • 197
  • Never done that before but maybe this can help you a bit http://mobisocial.stanford.edu/news/2011/03/control-3g-interface-with-your-own-application-on-andriod-phone/ . Rest of job should be done by checking NetworkManager + connection speed tests. Hope it helps – Pawel Cala Aug 23 '13 at 09:35

1 Answers1

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

pepe-pa
  • 552
  • 1
  • 5
  • 13