获取WIFI和移动数据的信号强度强度、信号、数据、WIFI

2023-09-12 06:33:59 作者:有了TA,就别懓‘我

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

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.

所以,我怎么能得到的速度或WiFi和移动的最佳信号强度 数据? 我怎么能在编程开关一关等。 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.

推荐答案

无线:

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();

那么你应该比较这信号电平,而如果WIFI信号好保持它打开,但如果手机更好断开无线网络

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