Android Get phone traffic usage

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

The key code is as follows:

1. Get a package manager. Packagemanager pm = Getpackagemanager ();//2. Traverse the phone operating system to get all the applications uidlist<applicationinfo> Appliactaioninfos = Pm.getinstalledapplications (0); for (ApplicationInfo applicationinfo:appliactaioninfos) {int UID = Applicationinfo.uid;    Get the software Uid//proc/uid_stat/10086long tx = Trafficstats.getuidtxbytes (UID);//Send the uploaded traffic Bytelong rx = Trafficstats.getuidrxbytes (UID)///Download traffic byte//method return value-1 means that the application does not generate traffic or the operating system does not support traffic statistics}trafficstats.getmobiletxbytes ( );//Get Mobile 3g/2g network upload total traffic trafficstats.getmobilerxbytes ();//Phone 2g/3g download Total traffic trafficstats.gettotaltxbytes ();//Phone All network interface including wifi,3g, 2g upload Total traffic trafficstats.gettotalrxbytes ();//Mobile phone all network interface including WIFI,3G, 2g download Total traffic

Android Get phone traffic usage

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: 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.