Issue
I want to calculate the amount of network usage/network traffic stats for my app in a month.
I can use TrafficStats to provides network traffic statistics, but the statistics returned by this class reset and start from zero after every reboot. I think about storing the statistics on the storage, but I want another way.
So I change to use NetworkStatsManager to calculate, but most of method required API >= 23.
So how can I do it with api below 23? Thank you.
Solution
you should persist the data from traffic stat in sqlite
at some time interval. And store the last reading just before Shutdown using
action android.intent.action.ACTION_SHUTDOWN
in broadcastreceiver. After restart, you should start storing the data again. This way, you will not lost the data. The solution works on all android version.
Answered By - Nitesh Verma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.