1 statistics on the traffic of Android architecture through a Trafficstats class can be directly obtained
Get total accepted Traffic trafficstats.gettotalrxbytes (),
Get total Send 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.
Therefore, the statistics of a program of traffic statistics, it is important to pay attention to the switch machine, and this boot is the first time after the start of 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 over all networks (including WiFi) */
Trafficstats.gettotalrxbytes ();
/** get the total number of packets received by the phone over all networks (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 that the phone sends over all networks (including WiFi) */
Trafficstats.gettotaltxpackets ();
/** gets the total number of bytes traffic (including WiFi) that is received by the program with the specified UID for the phone, using all network methods
Trafficstats.getuidrxbytes (UID);
/** gets the total number of bytes traffic (including WiFi) sent by the application that corresponds to the specified UID for the phone over all networks
Trafficstats.getuidtxbytes (UID);
}
public boolean Oncreateoptionsmenu (Menu menu) {
Getmenuinflater (). Inflate (R.menu.activity_main, menu);
return true;
}
}
Several applications in Android OS are collective, including (Android system, settings store, settings, System user interface, MIUI)
Os in the various modules of the traffic statistics are calculated to the OS 1000 traffic, if a module is not able to pull out problems, you can create an interface to calculate the respective.