计算Android中当前的移动连接速度?
我需要 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在存储接收到的总字节数之前记下时间,根据需要等待 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.