Android traffic statistics

Source: Internet
Author: User

1. A TrafficStats class can be used to collect statistics on traffic in the android architecture.
Get the total accepted traffic TrafficStats. getTotalRxBytes (),
Get the total sending traffic TrafficStats. getTotalTxBytes ());
Get the GPRS reception volume of a mobile phone that does not contain WIFI TrafficStats. getcyclerxbytes ());
Get the number of mobile phone GPRS sent without Wifi TrafficStats. getMobileTxBytes ());

Count the total number of recipients of a process. TrafficStats. getUidRxBytes (Uid ));
Count the total sending volume of a process. TrafficStats. getUidTxBytes (Uid ));

The traffic obtained is the statistics from the start time to the read time.
Therefore, when calculating the traffic statistics of a program, you must pay attention to the switch, and the number of times this program is started after the current start.

2 android TrafficStats class
Data in the first four read/proc/net/dev files
The following two interfaces measure the traffic of a process based on node data in the/proc/uid_stat/*** interface.

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 byte traffic received by the mobile phone through 2G/3G */
TrafficStats. getpolicerxbytes ();
/** Obtain the total number of data packets received by the mobile phone through 2G/3G */
TrafficStats. getMobileRxPackets ();
/** Get the total byte traffic sent by the mobile phone through 2G/3G */
TrafficStats. getMobileTxBytes ();
/** Obtain the total number of data packets sent by the mobile phone through 2G/3G */
TrafficStats. getMobileTxPackets ();
/** Get the total byte traffic received by the mobile phone in all network modes (including wifi )*/
TrafficStats. getTotalRxBytes ();
/** Obtain the total number of packets received by the mobile phone in all network modes (including wifi )*/
TrafficStats. getTotalRxPackets ();
/** Get the total byte traffic sent by the mobile phone in all network modes (including wifi )*/
TrafficStats. getTotalTxBytes ();
/** Obtain the total number of data packets sent by the mobile phone over all networks (including wifi )*/
TrafficStats. getTotalTxPackets ();
/** Obtain the total byte traffic (including wifi) received by the app corresponding to the specified UID on the mobile phone in all network modes )*/
TrafficStats. getUidRxBytes (uid );
/** Get the total byte traffic (including wifi) sent by the app corresponding to the specified UID on the mobile phone in all network modes )*/
TrafficStats. getUidTxBytes (uid );
}
Public boolean onCreateOptionsMenu (Menu menu ){
GetMenuInflater (). inflate (R. menu. activity_main, menu );
Return true;
}
}

There are several apps under Android OS collectively, including (Android system, set storage, settings, System User Interface, miui)

The traffic statistics of each module in the OS are counted as 1000 of the OS traffic. If a module fails, it cannot be identified. You can create interfaces to calculate the traffic separately.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.