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

发布于 2024-12-19 18:48:58 字数 776 浏览 4 评论 0原文

我需要 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 指“传送”。

I need the current mobile connectivity speed of an android device. I know how to get the speed link of the wifi connection, but not the mobile connection.

myWifiInfo.getLinkSpeed());

Been reading up on the TrafficStats class, but don't know what to calculate with the information given. For instance:

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 refers to "receiving" and TX refers to "transferring".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花落人断肠 2024-12-26 18:48:58

在存储接收到的总字节数之前记下时间,根据需要等待 10 到 20 秒,然后再次记下接收到的总字节数。现在找出字节数的差异并将其除以等待的秒数。结果将是您的速度(以每秒字节数为单位)。

Note time before storing total received bytes, wait for 10 to 20 secs whatever you like then again note total received bytes. Now find the difference in bytes and divide it with the waited number of seconds. The result will be your speed in Bytes per second.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文