Is it possible to collect the amount of data spent in a period of time?

Asked

Viewed 24 times

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.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.