Android Traffic statistics

Source: Internet
Author: User

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, here Android123 prompts you not to include WiFi
Static long Getmobilerxpackets ()//Gets the total number of packets received by the mobile connection
Static long Getmobiletxbytes ()//mobile The total number of bytes sent
Static long Getmobiletxpackets ()//mobile The total number of packets sent
Static long Gettotalrxbytes ()//Gets the total number of bytes accepted, including mobile and WiFi, etc.
Static long Gettotalrxpackets ()//Total number of accepted packets, including mobile and WiFi, etc.
Static long Gettotaltxbytes ()//Total number of bytes sent, including mobile and WiFi, etc.
Static long Gettotaltxpackets ()//total number of packets sent, including mobile and WiFi, etc.
static long getuidrxbytes (int uid)//Gets the number of accepted bytes for a network uid
static long getuidtxbytes (int uid)//Gets the number of bytes sent for a network UID
Finally the Android Development network reminds developers again that the Trafficstats class works on the firmware of Android 2.2 API level 8.

1 Android has a trafficstats class that can be directly obtained
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 statistics from one boot to one shutdown.
Therefore, to do a certain program of traffic statistics, be sure to pay attention to the switch machine, and this time after the boot is the first to start the program.

2 Android on top of the Trafficstats class
The data inside the first four read/proc/net/dev


The traffic in one of the subsequent processes is statistically/proc/uid_stat/*** data



Now the class library that Google gives is only able to read the power-on and receive traffic for an app.
It contains WiFi and GPRS.

Android Traffic statistics

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.