Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure data usage of my app

I'm developing an Android app which needs to download a lot of data.

To improve the usability, I'd like to measure the data traffic my app produces and give the users a hint if the app downloaded a specific amount of data.

My current idea: Sum all downloaded bytes together and react on a specified limit. However, as I downloaded things in many different situations and in many different positions in the code, is there any other possibility to measure the data usage per app?

AFAIK, sys/net/NETINTERFACE/statistics/rx_bytes reports the total amount of the whole system, so this is not a solution.

like image 329
SecStone Avatar asked Dec 10 '22 03:12

SecStone


1 Answers

However, as I downloaded things in many different situations and in many different positions in the code, is there any other possiblity to measure the data usage per app?

TrafficStats may be able to report things by UID. I say "may" because it seems tied to devices. I suspect that Android 3.0+ will consistently report by UID, but my 2.2 and 2.3 experience has been mixed.

Here is a sample application demonstrating recording this information.

like image 114
CommonsWare Avatar answered Dec 21 '22 11:12

CommonsWare