Software traffic usage data is saved in /proc/uid_stat/uid (user ID)/ below file
/proc/uid_stat/uid/tcp_send Upload Traffic
/PROC/UID_STAT/UID/TCP_RCV Download 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