【文件属性】:
文件名称:Android流量统计
文件大小:5.73MB
文件格式:ZIP
更新时间:2018-09-20 09:00:17
流量监控
/**
* 返回所有有互联网权限的应用的流量信息
*/
public List getTrifficInfos(){
//获取到配置权限信息的应用程序
List packageInfos=pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
//存放有Internet权限信息的应
List trifficInfos=new ArrayList();
for (PackageInfo info:packageInfos){
String [] permissions=info.requestedPermissions;
if (permissions!=null && permissions.length>0){
for (String permission:permissions){
if ("android.permission.INTERNET".equals(permission)){ //找到应用程序里面又网络权限
TrifficInfo trifficInfo=new TrifficInfo();
trifficInfo.setPackname(info.packageName);
trifficInfo.setAppname(info.applicationInfo.loadLabel(pm).toString());
trifficInfo.setIcon(info.applicationInfo.loadIcon(pm));
int uid=info.applicationInfo.uid;
trifficInfo.setRx(TrafficStats.getUidRxBytes(uid));
trifficInfo.setTx(TrafficStats.getUidTxBytes(uid));
trifficInfos.add(trifficInfo);
trifficInfo=null;
break;
}
}
}
}
return trifficInfos;
}