How to go about detecting data usage in the Android environment

前端 未结 1 721
情歌与酒
情歌与酒 2020-12-28 09:21

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

相关标签:
1条回答
  • 2020-12-28 10:04

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

    0 讨论(0)
提交回复
热议问题