How to measure data usage of my app Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to measure data usage of my app without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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.

Answer

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.

We are here to answer your question about How to measure data usage of my app - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji