11

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?

1 Answer 1

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).

3
  • 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? Commented Feb 28, 2011 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
    Commented Oct 16, 2012 at 21:00
  • Not working on device below JELLY_BEAN_MR2. developer.android.com/reference/android/net/…
    – karn
    Commented May 8, 2015 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.