I would like to be able to detect all forms of data usage using the Android environment. Is it possible to keep tabs on which applications call on say RTP vs WAP, etc. such that I can know at all times when data is being used by a native program or third-party app?
Asked
Active
Viewed 1.3k times
1 Answers
8
If you are talking about an Android API to monitor network statistics by application then such an API seems to have been added in Android 2.2 (Froyo).
The main class you'll need is TrafficStats.
You can use getUid{Rx|Tx}Bytes(int uid)
for the given process user ID (which you can get from ActivityManager.getRunningAppProcesses()
).
The API is very simple and simply gives you the total bytes received/sent, so you'll have to do some more work to keep track of hourly, daily, and monthly stats. Well, that all depends on your needs.
I haven't tried using it myself, so I cannot give you any more detail, nor do I know the supported devices (not all devices will support this as the API points out).

Peter Mortensen
- 30,738
- 21
- 105
- 131

rodion
- 14,729
- 3
- 53
- 55
-
hmm that does give me some direction. I appreciate it. But you said I can't use this for earlier versions? and there is no way to addrss this for earlier versions? just curious? – Dave Powell Feb 28 '11 at 21:17
-
can I get the RX/TX stats from ADB? or is the only way to access them is through an app. I would like to know if I could do something like ADB Shell cat proc/int_UID/net/dev > C:\netstats.txt ... but actually get the rx/tx stats from individual applications – Nefariis Oct 16 '12 at 21:00
-
Not working on device below JELLY_BEAN_MR2. http://developer.android.com/reference/android/net/TrafficStats.html#getUidRxBytes(int) – karn May 08 '15 at 06:24