1. 程式人生 > >android app 流量統計

android app 流量統計

sdn () ren 並且 無法 app HR 監聽 編程)

https://blog.csdn.net/yzy9508/article/details/48300265 | android 數據流量統計 - CSDN博客
https://blog.csdn.net/forlong401/article/details/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
https://blog.csdn.net/u012819339/article/details/50513387 | 【智能路由器】設備流量、網速統計及上下線提醒(基於netfilter編程) - CSDN博客
https://blog.csdn.net/yiranyinger/article/details/78062778 | Android 獲取手機整體流量使用情況以及某個應用的流量的統計 - CSDN博客
https://blog.csdn.net/w7849516230/article/details/71705835 | Android應用流量統計——NetworkStatsManager使用 - CSDN博客
https://developer.android.google.cn/reference/android/net/TrafficStats | TrafficStats | Android Developers
https://blog.csdn.net/u013205623/article/details/52860071 | TrafficStats類實現Android監聽網速 - CSDN博客
https://blog.csdn.net/focusjava/article/details/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 流量統計