gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 18:53:28 29 4
gpt4 key购买 nike

在我的应用程序中,我需要检查 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 - 获取WIFI和移动数据的信号强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18399364/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com