Android monitors the traffic of various programs

Source: Internet
Author: User
Public void getapptrafficlist () {// obtain information about all application software installed on the mobile phone and obtain the permission information packagemanager PM = getpackagemanager () in these software (); // obtain system application package management // obtain androidmanifest in each package. XML Information, its permissions, and so on list <packageinfo> pinfos = PM. getinstalledpackages (packagemanager. get_uninstalled_packages | packagemanager. get_permissions); // traverse each application package information for (packageinfo info: pinfos) {// request androidmanifest corresponding to each package. permission in XML string [] premissions = info. requestedper Missions; If (premissions! = NULL & premissions. length> 0) {// find the application for network services (string premission: premissions) {If ("android. permission. internet ". equals (premission) {// obtain the process ID of each application in the operating system int uid = info. applicationinfo. UID; // If-1 is returned, this method is not supported. Note that it must be a long RX = trafficstats of more than 2.2. getuidrxbytes (UID); // If-1 is returned, this method is not supported. Note that it must be a long Tx = trafficstats of more than 2.2. getuidtxbytes (UID); If (RX <0 | TX <0) {continue;} else {// toast. maketext (this, info. applicationinfo. loadlabel (PM) + "consumed traffic --" + // formatter. formatfilesize (this, RX + Tx), toast. length_short );}}}}}}

  

Related Article

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.