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.