Use of the Android traffic statistics Trafficstats class

Source: Internet
Author: User

Transfer from http://gundumw100.iteye.com/blog/1294167

For Android traffic statistics in the 2.2 version of the new Trafficstats class can be easily obtained, in fact, the Trafficstats class is also read Linux provided by the file object system type of text to parse. 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 LongGetmobilerxbytes ()//gets the total number of bytes received via the mobile connection, not including WiFi    Static LongGetmobilerxpackets ()//get the total number of packets received by the mobile connection    Static LongGetmobiletxbytes ()//total number of bytes sent by mobile    Static LongGetmobiletxpackets ()//total number of packets sent by mobile    Static LongGettotalrxbytes ()//gets the total number of accepted bytes, including mobile and WiFi, etc.    Static LongGettotalrxpackets ()//total number of accepted packets, including mobile and WiFi    Static LongGettotaltxbytes ()//total number of bytes sent, including mobile and WiFi    Static LongGettotaltxpackets ()//the total number of packets sent, including mobile and WiFi, etc.    Static LongGetuidrxbytes (intUid//gets the number of accepted bytes for a network uid    Static LongGetuidtxbytes (intUid//Gets the number of bytes sent for a network UID

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 the statistics from the first startup program to the last start. Not the "Statistics from this boot to the shutdown" in this article!

For example, note that the units obtained here are "KB"

     Public LongGettotalrxbytes () {//gets the total number of accepted bytes, including mobile and WiFi, etc.            returnTrafficstats.gettotalrxbytes () ==trafficstats.unsupported?0: (Trafficstats.gettotalrxbytes ()/1024); }           Public LongGettotaltxbytes () {//total number of bytes sent, including mobile and WiFi            returnTrafficstats.gettotaltxbytes () ==trafficstats.unsupported?0: (Trafficstats.gettotaltxbytes ()/1024); }           Public LongGetmobilerxbytes () {//gets the total number of bytes received via the mobile connection, not including WiFi            returnTrafficstats.getmobilerxbytes () ==trafficstats.unsupported?0: (Trafficstats.getmobilerxbytes ()/1024); }  

Use of the Android traffic statistics Trafficstats class

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.