1
I’m making an Android application and I need to get the amount of data used by the person in a specific period of time, on Androids that use the level 21 (Lollipop) Apis up to the current one (Nougat).
I searched and found two classes, one of them is Trafficstats that through it I can get all the amount of data spent since the cell phone boot, IE, every time the phone is turned off and on the value returned goes to zero, this class is supported by Apis 21+(Lollipop). So to make the collection properly my app would need to always stay run which doesn’t always happen because the user can choose to close it.
The other class is Networkstatsmanager which does exactly what I need, but only works for Apis 23+(Marshmallow).
So, is there any other class or tool that I can use that works similar to Networkstatsmanager but is compatible with previous Android versions?
I am far from being a deep connoisseur of the subject. But still I wanted to give a hint/hint: even if your APP is not running every time, you can save the value obtained from
TrafficStats
at each execution. So when the APP opens again, you can compare the current and previous value and interpolate the variation between these ranges to cherish traffic in any period of time. This way, the user will get a better result the more he uses his APP, but still manages to get an approximate response even if he uses little.– Luiz Vieira