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 code is as follows
//1. Gets a package manager. Packagemanager pm = Getpackagemanager ();//2. Traverse the phone operating system to get all the application's user ID (uid )list<applicationinfo> Appliactaioninfos = pm.getinstalledapplications (0); for (ApplicationInfo applicationinfo:appliactaioninfos) {int uid = APPLICATIONINFO.UID;//Get app User ID (uid ) //proc/uid_stat/10086 //Send the uploaded traffic to byte Long tx = Trafficstats.getuidtxbytes (UID);//downloads of traffic byte Long rx = trafficstats.getuidrxbytes (UID);//Method return value-1 means that the application does not generate traffic or the operating system does not support traffic statistics} trafficstats.gettotaltxbytes ();//Mobile phone all network interface including WIFI,3G, 2g upload Total trafficTrafficstats.gettotalrxbytes ()///Mobile phone all network interface including WIFI,3G, 2g download Total traffic Trafficstats.getmobiletxbytes ();//Get total traffic from mobile 3g/2g network uploadsTrafficstats.getmobilerxbytes ();//Mobile 2g/3g download Total traffic
|
Statistics mobile phone traffic