I am trying to fetch mobile data usage using TrafficStats.
Example:
mobileDataUsage = TrafficStats.getMobileRxBytes() +TrafficStats.getMobileTxBytes()
totalUsage = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes()
In few devices it is working absolutely fine. In Nexus 5X I am getting totalUsage but mobileDataUsage is always 0, TrafficStats.getMobileRxBytes()
and TrafficStats.getMobileTxBytes()
always return 0.
You most probably are seeing the issue described at https://code.google.com/p/android/issues/detail?id=78924 .
The docs for TrafficStats says the bytes returned "always increases monotonically since device boot", but that is indeed not the case for at least Android 5-7. Often the methods return 0 and then suddenly start counting from the number they used to have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With