How to measure mobile data traffic on Android

I am developing an application that measures the data traffic received using the mobile data interface (without Wi-Fi) from all processes. In addition, this counter must be associated with a date range, i.e. From March 1 and April 1.

I read about the TrafficStats class, but the documentation does not mention when it is statistics.

This is my first question, and I really appreciate your help.

thanks

+4
source share
1 answer

I read about the TrafficStats class, but the documentation does not mention when it is statistics.

β€œFrom when” doesn't matter to you. Take a reading at a specific point in time, do another reading at a later point in time, and the difference between them is the bandwidth consumed between these two points in time.

In addition, this counter must be associated with a date range, i.e. from March 1 and April 1.

You will need to deal with this yourself, most likely, check the amount of bandwidth consumption so often (for example, every 4 hours through the AlarmManager ), store the results in a database and then use this information to determine the bandwidth consumed over long periods of time.

+1
source

Source: https://habr.com/ru/post/1440912/


All Articles