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() //总的发送字节数,包含Mobile和WiFi等 static long getTotalTxPackets() //发送的总数据包数,包含Mobile和WiFi等 static long getUidRxBytes(int uid) //获取某个网络UID的接受字节数 static long getUidTxBytes(int uid) //获取某个网络UID的发送字节数 你自己去理算法
myuid是你的应用所有的uid,这个根据ActivityManager可以获取runing的程序获取到
代码没有详细的给你,公司工作写的代码,没法抠出来,大概就是先获取uid,然后根据那个方法获取接收流量
TrafficStats.getUidTxBytes(myuid);这个是发送流量。
这些是指开机开始计的,你想统计月什么的,自己写个方法保存叠加就是
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() //总的发送字节数,包含Mobile和WiFi等
static long getTotalTxPackets() //发送的总数据包数,包含Mobile和WiFi等
static long getUidRxBytes(int uid) //获取某个网络UID的接受字节数
static long getUidTxBytes(int uid) //获取某个网络UID的发送字节数
你自己去理算法
反之,你自己逻辑去,我觉着挺好实现的,就是花时间写下判断的算法
如果你有什么异议,提出来,或许我的方法有错误,想的粗糙