Statistics mobile phone traffic

Source: Internet
Author: User

Software traffic usage data is saved in /proc/uid_stat/uid (user ID)/ below file


/proc/uid_stat/uid/tcp_send Upload Traffic
/PROC/UID_STAT/UID/TCP_RCV Download Traffic


The code is as follows

//1. Gets a package manager. Packagemanager pm = Getpackagemanager ();//2. Traverse the phone operating system to get all the application's user ID (uid )list<applicationinfo> Appliactaioninfos = pm.getinstalledapplications (0); for (ApplicationInfo applicationinfo:appliactaioninfos) {int uid = APPLICATIONINFO.UID;//Get app User ID (uid ) //proc/uid_stat/10086 //Send the uploaded traffic to byte
Long tx = Trafficstats.getuidtxbytes (UID);//downloads of traffic byte  Long rx = trafficstats.getuidrxbytes (UID);//Method return value-1 means that the application does not generate traffic or the operating system does not support traffic statistics} trafficstats.gettotaltxbytes ();//Mobile phone all network interface including WIFI,3G, 2g upload Total trafficTrafficstats.gettotalrxbytes ()///Mobile phone all network interface including WIFI,3G, 2g download Total traffic
Trafficstats.getmobiletxbytes ();//Get total traffic from mobile 3g/2g network uploadsTrafficstats.getmobilerxbytes ();//Mobile 2g/3g download Total traffic

Statistics mobile phone traffic

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.