android擷取手機流量使用方式

來源:互聯網
上載者:User

標籤:android   trafficstats   流量統計   

軟體流量使用資料儲存在 /proc/uid_stat/uid(使用者id)/ 下面檔案中


/proc/uid_stat/uid/tcp_send        上傳流量
/proc/uid_stat/uid/tcp_rcv         下載流量


關鍵代碼如下:

//1.擷取一個包管理器。PackageManager pm = getPackageManager();//2.遍曆手機作業系統 擷取所有的應用程式的uidList<ApplicationInfo> appliactaionInfos = pm.getInstalledApplications(0);for(ApplicationInfo applicationInfo : appliactaionInfos){int uid = applicationInfo.uid;    // 獲得軟體uid//proc/uid_stat/10086long tx = TrafficStats.getUidTxBytes(uid);//發送的 上傳的流量bytelong rx = TrafficStats.getUidRxBytes(uid);//下載的流量 byte//方法傳回值 -1 代表的是應用程式沒有產生流量 或者作業系統不支援流量統計}TrafficStats.getMobileTxBytes();//擷取手機3g/2g網路上傳的總流量TrafficStats.getMobileRxBytes();//手機2g/3g下載的總流量TrafficStats.getTotalTxBytes();//手機全部網路介面 包括wifi,3g、2g上傳的總流量TrafficStats.getTotalRxBytes();//手機全部網路介面 包括wifi,3g、2g下載的總流量


android擷取手機流量使用方式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.