My Android app (running Android 10) uses network traffic statistics.
When my device is on Wifi, TrafficStats.getMobileTxBytes and ...getMobileRxBytes return always 0.
When it switches on Cellular network, returned values look good.
Any idea or solution?
You are using
TrafficStats.getMobileTxByte
From the docs:
As you say:
Yes that's because when the Cell Network is off, no mobile (cell) data is used, therefore 0.
You can use this to get the data used by the whole device:
You can use the below if you want to get non-cellular traffic:
https://developer.android.com/reference/android/net/TrafficStats#getTotalRxBytes()