0

I need to get the amount of data i.e. internet usage over periods of one month. I have been doing some research and found the TrafficStats class. However, it seems confusing. What is the difference between getUidRxBytes() and getUidRxPackets(). How can I get the data used over a period of one month?

Nikhil
  • 3,711
  • 8
  • 32
  • 43
Gerardo Soriano
  • 69
  • 1
  • 10

1 Answers1

0

Use the library android.net.TrafficStats to get the necessary information. You'll have to build an algorithm to calculate that the use of average.

Example:

long appDataUsage = android.net.TrafficStats.getUidRxBytes(UID);
long total =  android.net.TrafficStats.getTotalRxBytes();
  • But I am only concerned with mobile networks ie- 3G, 4G, And as far as I understand, those methods include WIFI networks – Gerardo Soriano Sep 25 '16 at 04:30
  • You're right, the data is mixed. However, you can monitor the change to Wifi or 3G. – Filipe Henrique Sep 25 '16 at 04:39
  • I've been reading the documentation and found that getMobileRxBytes() returns the data received over 3G,4G,,GPRS. However, the counter gets reset after the phone shuts down. Would you recommend setting up a db to store this data? – Gerardo Soriano Sep 25 '16 at 04:47
  • I recommend saving the data in the database, but can be used SharedPreferences. – Filipe Henrique Sep 25 '16 at 05:00
  • Thank you! One last question, and I apologize for my ignorance, but how do companies like Verizon measure the data usage? Do they add up the receive and sent(transmit) value or either of them? – Gerardo Soriano Sep 25 '16 at 05:02
  • I do not quite understand how it's done by companies, but they have a lot of information about your sim-card GSM that is logged in their network. With their identification they can make the amount of data you are sending and receiving for their network. – Filipe Henrique Sep 25 '16 at 05:10
  • I'll keep you posted on how it goes! – Gerardo Soriano Sep 25 '16 at 06:04