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.
source share