Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to go about detecting data usage in the Android environment

Tags:

android

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?

like image 697
Dave Powell Avatar asked Jan 27 '11 01:01

Dave Powell


1 Answers

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

like image 137
rodion Avatar answered Oct 04 '22 05:10

rodion