I am developing an application that allows you to check the statistics of Wi-Fi and mobile traffic on Android. This is how I get statistics:
long mobileStats = TrafficStats.getMobileRxBytes() + TrafficStats.getMobileTxBytes(); long wifiStats = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes() - mobileStats;
Unfortunately, wifiStats here seems more than Wi-Fi just because even when I turn off Wi-Fi on my smartphone, it gets a lot of data. I think getTotalRxBytes() and getTotalTxBytes() count bytes sent and received on all network interfaces.
I searched on the Internet many times how to get traffic statistics only on Wi-Fi, but I canβt find a way.
I am happy to accept any help.
source share