gpt4 book ai didi

android - 如何检查设备连接的 wifi 互联网连接速度?

转载 作者:行者123 更新时间:2023-11-29 18:11:16 25 4
gpt4 key购买 nike

我可以用这个检查设备是否连接到 wifi。

public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) activity
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();

if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}

但是,我想检查 wifi 连接速度,例如 Ping。我想根据这个 ping 号码来设置一些变量。像这样,

public int internetspeed(){
checking...
return speed;
}

谁能给我教程或例子?

最佳答案

这段代码将为您完成这项工作

    WifiManager wifiManager = Context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
Integer linkSpeed = wifiInfo.getLinkSpeed(); //measured using WifiInfo.LINK_SPEED_UNITS
}

关于android - 如何检查设备连接的 wifi 互联网连接速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10528831/

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