Android Traffic Statistics Trafficstats class

Source: Internet
Author: User

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 long  getmobilerxbytes ()  //Gets the total number of bytes received via the mobile connection, not including wifistatic long  getmobilerxpackets ()  // Gets the total number of packets received by the mobile connection static long  getmobiletxbytes ()  //mobile Total Bytes sent static long  getmobiletxpackets ()  //mobile Total Packets sent static long  gettotalrxbytes ()  //Gets the total number of bytes accepted, including mobile and WiFi static long  Gettotalrxpackets ()  //Total number of accepted packets, including mobile and WiFi static long  gettotaltxbytes ()  //Total Send bytes, Contains static long gettotaltxpackets (), such as mobile and WiFi  , the total number of packets sent, including mobile and WiFi static long  getuidrxbytes ( int uid)  //Gets the number of bytes accepted for a network uid static long  

Total accepted Traffic trafficstats.gettotalrxbytes (),
Total outgoing traffic trafficstats.gettotaltxbytes ());
Mobile Phone GPRS receiving trafficstats.getmobilerxbytes () without wifi;
Mobile phone GPRS send volume trafficstats.getmobiletxbytes () not including WiFi;
The total received trafficstats.getuidrxbytes (UID) of a process);
The total send volume trafficstats.getuidtxbytes (Uid) of a process);
These are the statistics from the first start of the program to the last start. Not the "Statistics from this boot to the shutdown" in this article! For an example of
usage, note that the units obtained here are "KB"

Public long Gettotalrxbytes () {  //Gets the total number of bytes accepted, including mobile and WiFi    return trafficstats.gettotalrxbytes () = = Trafficstats.unsupported?0: (Trafficstats.gettotalrxbytes ()/1024);  }  Public long Gettotaltxbytes () {  //Total number of bytes sent, including mobile and WiFi    return trafficstats.gettotaltxbytes () = = Trafficstats.unsupported?0: (Trafficstats.gettotaltxbytes ()/1024);  }  Public long Getmobilerxbytes () {  //Gets the total number of bytes received via mobile connection, not including WiFi    return trafficstats.getmobilerxbytes () = = Trafficstats.unsupported?0: (Trafficstats.getmobilerxbytes ()/1024);  

Reference Link: http://blog.csdn.net/qjbagu/article/details/7102730?locationNum=11

Android_net_trafficstats.cpp source Download Link: http://download.csdn.net/detail/klcf0220/9654458

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.