0

I need to find how much data is consumed by single webservice/API call. I have searched a lot and found this:

commonsguy/cw-andtuning
How can I find the data usage on a per-application basis on Android?

But these gives me DataUsage of whole application, i want to find it for single API/webservice call.

Community
  • 1
  • 1
Ravi
  • 34,851
  • 21
  • 122
  • 183

2 Answers2

0

THere is no built in way to do that. You'd need to do it yourself, by adding the size of the data returned each time you call it.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

If you execute one API call at the time, then you might look into android.net.TrafficStats. Inside it, there is a method android.net.TrafficStats#getUidTxPackets(int uid) and android.net.TrafficStats#getUidRxPackets(int uid). You might obtain your application uid from android.content.pm.ApplicationInfo#uid.

Get the value before a call, then get it once again after a call, and count the difference.

However, be advised:

Before android.os.Build.VERSION_CODES#JELLY_BEAN_MR2, this may return UNSUPPORTED

R. Zagórski
  • 20,020
  • 5
  • 65
  • 90