问题
I was wondering if I can do network traffic monitoring per android application?
Basically see which app is receiving/sending how much data?
I know there are many apps which already do that but I want to know how to do it.
回答1:
Well you surely can. A very simple way is to use the TrafficStats class. It can manage per app (more formally, per UID) But the problem is, it can return UNSUPPORTED
. When this happens, I don't think you will have some easy (i.e. using the high level Java language) method to get the network traffic data you need.
回答2:
Not sure if it can be implemented in Java as I imagine you need to access some low-level Operating system functions which are just not available in Java (but don't quote me on this!).
The obvious way I see of doing this is through C language and the Android Native Development Kit.
来源:https://stackoverflow.com/questions/7181045/network-traffic-monitoring-per-android-application