gpt4 book ai didi

android - 计算Android中当前的移动连接速度?

转载 作者:搜寻专家 更新时间:2023-11-01 09:10:56 25 4
gpt4 key购买 nike

我需要 Android 设备的当前移动连接速度。我知道如何获取 wifi 连接的速度链接,但不知道移动连接。

myWifiInfo.getLinkSpeed());

一直在阅读 TrafficStats 类,但不知道如何使用给定的信息进行计算。例如:

TrafficStats ts = new TrafficStats();
Log.i("trace", "getMobileRxBytes : " + ts.getMobileRxBytes());
Log.i("trace", "getMobileRxPacets : " + ts.getMobileRxPackets());
Log.i("trace", "getMobileTxBytes : " + ts.getMobileTxBytes());
Log.i("trace", "getMobileTxPackets : " + ts.getMobileTxPackets());

Log.i("trace", "getTotalRxBytes : " + ts.getTotalRxBytes());
Log.i("trace", "getTotalRxPackets : " + ts.getTotalRxPackets());
Log.i("trace", "getTotalTxBytes : " + ts.getTotalTxBytes());
Log.i("trace", "getTotalTxPackets : " + ts.getTotalTxPackets());

Rx是指“接收”,TX是指“传送”。

最佳答案

记下存储接收到的总字节数之前的时间,等待 10 到 20 秒,无论您喜欢什么,然后再次记下接收到的总字节数。现在找到以字节为单位的差异并将其除以等待的秒数。结果将是您的速度(以字节/秒为单位)。

关于android - 计算Android中当前的移动连接速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8408694/

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