How to monitor the flow of each program by Android programming _android

Source: Internet
Author: User

This article describes the Android programming approach to monitoring the flow of each program. Share to everyone for your reference, specific as follows:

public void Getapptrafficlist () {//Get all the information on the application software installed on the mobile phone, and obtain the permission information in the software Packagemanager Pm=getpackagemanager ()/Get the system Application package Management//Get androidmanifest.xml information within each package, its permissions, etc. list<packageinfo> pinfos=pm.getinstalledpackages (Packagemana Ger. Get_uninstalled_packages | 
  Packagemanager.get_permissions); Traverse each application package information for (PackageInfo Info:pinfos) {//request permissions within each package corresponding to Androidmanifest.xml string[] Premissions=info.reques 
   Tedpermissions; 
     if (premissions!=null && premissions.length>0) {//Find application for network services for (String premission:premissions) { if ("Android.permission.INTERNET". Equals (Premission)) {//get the process ID int for each application within the operating system Uid=info.applicationin 
      Fo.uid; 
      If return-1, the representative does not support the use of this method, note must be more than 2.2 long rx=trafficstats.getuidrxbytes (UID); 
      If return-1, the representative does not support the use of this method, note must be more than 2.2 long tx=trafficstats.getuidtxbytes (UID); 
      if (rx<0 | | tx<0) {continue; }else{//Toast.maketext (this, info.applicationInfo.loadLaBel (PM) + "Consumption of flow--" +//Formatter.formatfilesize (this, rx+tx), toast.length_short); } 
     } 
    } 
   } 
  } 
}

I hope this article will help you with your Android programming.

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.