android app 流量統計

來源:互聯網
上載者:User

標籤:run   並且   ref   ons   manager   如何   --   java   thread   

48300265 | android 資料流量統計 - CSDN部落格
8440160 | android如何開發流量監視軟體 - CSDN部落格
https://stackoverflow.com/questions/12613402/android-statistic-3g-traffic-for-each-app-how | android statistic 3g traffic for each APP, how? - Stack Overflow
50513387 | 【智能路由器】裝置流量、網速統計及上下線提醒(基於netfilter編程) - CSDN部落格
78062778 | Android 擷取手機整體流量使用方式以及某個應用的流量的統計 - CSDN部落格
71705835 | Android應用流量統計——NetworkStatsManager使用 - CSDN部落格
https://developer.android.google.cn/reference/android/net/TrafficStats | TrafficStats  |  Android Developers
52860071 | TrafficStats類實現Android監聽網速 - CSDN部落格
52195001 | Android 流量最佳化(一):模組化流量統計 - CSDN部落格
https://developer.android.google.cn/ | Android Developers

 

 

 

PR: 按照應用統計流量消耗情況?

監聽 攔截 網路 流量

TrafficStats.
--2.2之後引入了一個新的 android.net.TrafficStats類可以做到網路流量統計,可以統計總流量也可以統計單個進程的流量

Android系統將放流量資料資訊儲存在檔案/proc/net/xt_qtaguid/stats 中(見源碼)

使用TrafficStats.setThreadTag(int tag)方法標記的產生流量的線程,參數tag是上面模組相關的tag;@See TrafficStats;
NOTE:1、一個線程同時只會有一個有效tag,並且不會傳遞,依賴包啟動了新線程訪問網路則需要依賴方提供標記支援;2、native層socket、webview產生的流量無法使用此方法標記;


TrafficStats.getUidRxBytes(myuid);
myuid是你的應用所有的uid,這個根據ActivityManager可以擷取runing的程式擷取到
大概就是先擷取uid,然後根據那個方法擷取接收流量
TrafficStats.getUidTxBytes(myuid);這個是發送流量。
這些是指開機開始計的,你想統計月什麼的,自己寫個方法儲存疊加就是

static long getMobileRxBytes() //擷取通過Mobile串連收到的位元組總數,不包含WiFi
static long getMobileRxPackets() //擷取Mobile串連收到的資料包總數,不包含WiFi
static long getMobileTxBytes() //Mobile發送的總位元組數
static long getMobileTxPackets() //Mobile發送的總資料包數
static long getTotalRxBytes() //擷取總的接受位元組數,包含Mobile和WiFi等
static long getTotalRxPackets() //總的接受資料包數,包含Mobile和WiFi等
static long getTotalTxBytes() //總的發送位元組數,包

android app 流量統計

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.