14

在我的应用程序中,我需要检查 WiFi 和移动数据的连接速度,然后进行比较,然后切换到速​​度最高的网络。

  • 那么如何才能获得wifi和移动数据的速度或最佳信号强度呢?
  • 如何以编程方式关闭一个,另一个打开。

请帮帮我。一个样本会很有帮助。

4

1 回答 1

33

无线上网:

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

如果是移动设备,它应该可以工作:

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

然后你应该比较这个信号水平,如果WIFI信号更好保持打开,但如果手机更好断开wifi

于 2013-08-23T10:03:56.737 回答