Ikrom
Ikrom

Reputation: 5123

On Android how to count 3G, WiFi internet traffic for daily, weekly, monthly?

I've started recently learning android, and in my current project i need to count daily, weekly, monthly 3G and WiFi internet traffic. By now i could find that:

long totalRecievedBytes = TrafficStats.getTotalRxBytes();
long totalTransmittedBytes = TrafficStats.getTotalTxBytes();
String allTraffic = humanReadableByteCount(totalRecievedBytes + totalTransmittedBytes);
TextView tv = (TextView) findViewById(R.id.traffic_3g_all);
tv.setText(allTraffic);

i've seen netcounter app and it writes all traffics data to phone's memory. when launched reads traffic data from memory.

what kind of ways exist to collect information about 3G, WiFi internet traffic usage for daily, weekly, monthly?

thanks, any answers appreciated.

Upvotes: 1

Views: 3379

Answers (1)

Nick
Nick

Reputation: 351

If you look at the class reference here TrafficStats Android Reference, the system does not keep track of it by month, day, or week and some devices do not support it all. So, your app would need to determine if it is supported, and then read the stats at some periodic interval and keep track of them itself. I did reaad of a way to reset the stats in the documentation, but I would see if there isn't some hard wired in settings that resets this counter. You would probably want to have a service run at boot to collect this data, see this Question to learn how to do that.

Upvotes: 1

Related Questions