【发布时间】:2012-09-06 14:15:25
【问题描述】:
我正在尝试测量我的应用收到了多少字节。 我是这样做的:
long receivedBytesBefore = TrafficStats.getTotalRxBytes();
...
doSomething();
...
long receivedBytesAfter = TrafficStats.getTotalRxBytes();
long receivedBytes = receivedBytesAfter - receivedBytesBefore;
我的问题是 getTotalRxBytes() 总是返回 0。所以无论我做什么,我的结果都是 0。 我发现该方法只是读取一些文本文件,例如
/sys/class/net/rmnet0/statistics/rx_bytes
所以我查看了这些文件,它们都只包含“0”。
我错过了什么还是我必须以某种方式激活此功能? 有没有其他方法可以测量我的应用收到了多少字节?
我的 Android 设备是运行 Android 2.3.3 的三星 Galaxy Ace S5830
【问题讨论】:
标签: android networking