Android.net.TrafficStats class, provides a variety of static methods, can be called directly to get, return type is long, if return equals-1 for unsupported current device does not support statistics.
Static long Getmobilerxbytes ()//Gets the total number of bytes received via the mobile connection, here Android123 prompts you not to include WiFi
Static long Getmobilerxpackets ()//Gets the total number of packets received by the mobile connection
Static long Getmobiletxbytes ()//mobile The total number of bytes sent
Static long Getmobiletxpackets ()//mobile The total number of packets sent
Static long Gettotalrxbytes ()//Gets the total number of bytes accepted, including mobile and WiFi, etc.
Static long Gettotalrxpackets ()//Total number of accepted packets, including mobile and WiFi, etc.
Static long Gettotaltxbytes ()//Total number of bytes sent, including mobile and WiFi, etc.
Static long Gettotaltxpackets ()//total number of packets sent, including mobile and WiFi, etc.
static long getuidrxbytes (int uid)//Gets the number of accepted bytes for a network uid
static long getuidtxbytes (int uid)//Gets the number of bytes sent for a network UID
Finally the Android Development network reminds developers again that the Trafficstats class works on the firmware of Android 2.2 API level 8.
1 Android has a trafficstats class that can be directly obtained
Total accepted Traffic trafficstats.gettotalrxbytes (),
Total send Traffic trafficstats.gettotaltxbytes ());
Mobile phone GPRS receiving amount trafficstats.getmobilerxbytes () not including WiFi;
Mobile phone GPRS sending amount trafficstats.getmobiletxbytes () not including WiFi;
The total receive volume of a process trafficstats.getuidrxbytes (Uid));
The total sending volume of a process trafficstats.getuidtxbytes (Uid));
These are statistics from one boot to one shutdown.
Therefore, to do a certain program of traffic statistics, be sure to pay attention to the switch machine, and this time after the boot is the first to start the program.
2 Android on top of the Trafficstats class
The data inside the first four read/proc/net/dev
The traffic in one of the subsequent processes is statistically/proc/uid_stat/*** data
Now the class library that Google gives is only able to read the power-on and receive traffic for an app.
It contains WiFi and GPRS.
Android Traffic statistics