在我的应用程序中,我需要检查WiFi和移动数据的连接速度,然后进行比较,然后切换到速度最快的网络。
- 那么我该如何获取WiFi和移动数据的速度或最佳信号强度?
- 我该如何通过程序将其中一个关闭并将另一个打开?
请帮帮我。 提供示例会很有帮助。
在我的应用程序中,我需要检查WiFi和移动数据的连接速度,然后进行比较,然后切换到速度最快的网络。
请帮帮我。 提供示例会很有帮助。
无线网络:
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连接。
android.telephony.CellInfoLte无法强制转换为android.telephony.CellInfoGsm
。 - vuhung3990