I am developping an app which allows to check wifi and mobile traffic stats on android. That's how I get the stats :
long mobileStats = TrafficStats.getMobileRxBytes() + TrafficStats.getMobileTxBytes();
long wifiStats = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes() - mobileStats;
Unfortunately, wifiStats
here seems to be more than wifi only because even when i disable wifi on my smartphone, it gets me tons of data.
I think that getTotalRxBytes()
and getTotalTxBytes()
are counting bytes transmitted and received on all Network Interfaces.
I searched a lot on the web how to get traffic stats only on wifi but i cannot find a way.
I would gladly accept any help.
I had the same problem a few years back and solved this by reading the system files directly.
Hope it helps!