1 Android through schema traffic statistics Trafficstats class can be directly obtained
Get total traffic to accept trafficstats.gettotalrxbytes (),
Get total outgoing traffic trafficstats.gettotaltxbytes ());
Get GPRS receive Trafficstats.getmobilerxbytes () for mobile phones that do not include WiFi;
Get GPRS Send volume trafficstats.getmobiletxbytes () for mobile phones that do not include WiFi;
Statistics the total receive volume of a process trafficstats.getuidrxbytes (Uid));
Statistics the total sending volume of a process trafficstats.getuidtxbytes (Uid));
These acquired traffic is counted from one boot to the time of reading.
So. When counting the traffic statistics of a certain program, be sure to pay attention to the switch machine. And this time after the boot is the first several times to start the program.
2 Android Trafficstats Class
The data inside the first four read/proc/net/dev
The following two interfaces to a process of traffic statistics is the/proc/uid_stat/*** interface inside the node data
Package Cn.sunzn.trafficmanger;
Import android.app.Activity;
Import Android.net.TrafficStats;
Import Android.os.Bundle;
Import Android.view.Menu;
public class Mainactivity extends Activity {
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
/** get the total number of bytes that the phone receives through 2G/3G */
Trafficstats.getmobilerxbytes ();
/** get the total number of packets received by the phone via 2g/3g */
Trafficstats.getmobilerxpackets ();
/** gets the total number of bytes of traffic sent through 2G/3G */
Trafficstats.getmobiletxbytes ();
/** get the total number of packets sent by the phone via 2g/3g */
Trafficstats.getmobiletxpackets ();
/** get the total number of bytes of traffic received by the phone via all networks (including WiFi) */
Trafficstats.gettotalrxbytes ();
/** get the total number of packets received by the phone over the network (including WiFi) */
Trafficstats.gettotalrxpackets ();
/** get the total number of bytes of traffic that the phone sends over all networks (including WiFi) */
Trafficstats.gettotaltxbytes ();
/** get the total number of packets sent over the network by the phone (including WiFi) */
Trafficstats.gettotaltxpackets ();
/** Gets the phone specifies the UID corresponding to the total number of bytes of traffic received via all networks (including WiFi) */
Trafficstats.getuidrxbytes (UID);
/** gets the total number of bytes of traffic (including WiFi) sent by the corresponding application over the entire network via the phone specified UID */
Trafficstats.getuidtxbytes (UID);
}
public boolean Oncreateoptionsmenu (Menu menu) {
Getmenuinflater (). Inflate (R.menu.activity_main, menu);
return true;
}
}
There are several applications in Android OS that are collective, including (Android system, settings store, settings, System user interface, MIUI)
The flow statistics of each module in the OS are counted to the OS 1000 process, so you can create an interface calculation if a module doesn't pull the problem.
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Android Traffic statistics