The issue is known: when wifi is up, TrafficStats.getMobileRxBytes() and getMobileTxBytes() return 0 since Lollipop (https://issuetracker.google.com/issues/37009612). I found a workaround ignoring zero values, except that on some devices (e.g Samsung 5G), when on wifi, we get non-0 values. It brings only rmnet1 interface value traffic (rmnet1 is for VoLTE, rmnet0 for normal data).
1/ why only on Samsung devices? while it seems to be handled by Android OS
2/ another observation still on Samsung 5G devices (at least on Samsung S20): when wifi is down, cell counter (all cell traffic since boot: rmnet0 + rmnet1) is inconsistent, sometime we get a value V1, sometime a value V2 (different from V1)
A similar experience?
I haven't used 5G enabled devices, but as of i know, using
NetworkStats.Bucket
's object we can query for RxBytes and TxBytes with the help ofquerySummaryForDevice()
which takes around 4 parametersTELEPHONY_SERVICE
).you can get subscriberID using below code
This worked for me to get the RxBytes and TxBytes.