TrafficStats.getMobileRxBytes()和TrafficStats.getMobileTxBytes()在Nexus 5x中始终返回0

时间:2016-06-09 10:51:23

标签: android android-trafficstats

我正在尝试使用TrafficStats获取移动数据使用情况。

示例:

mobileDataUsage = TrafficStats.getMobileRxBytes()+ TrafficStats.getMobileTxBytes()

totalUsage = TrafficStats.getTotalRxBytes()+ TrafficStats.getTotalTxBytes()

在少数设备中它工作得非常好。在 Nexus 5X 中,我获得totalUsage但mobileDataUsage始终为0,TrafficStats.getMobileRxBytes()TrafficStats.getMobileTxBytes()始终返回0.

1 个答案:

答案 0 :(得分:2)

您很可能会看到https://code.google.com/p/android/issues/detail?id=78924所述的问题。

docs for TrafficStats表示返回的字节“自设备启动后总是单调增加”,但至少Android 5-7确实不是这样。通常这些方法会返回0,然后突然从它们曾经拥有的数字开始计数。