Android流量统计TrafficStats类的使用
static long getMobileRxBytes() //获取通过Mobile连接收到的字节总数,这里Android123提示大家不包含WiFi
static long getMobileRxPackets() //获取Mobile连接收到的数据包总数
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的发送字节数
long receivedBytesBefore = TrafficStats.getTotalRxBytes();
...
doSomething();
...
long receivedBytesAfter = TrafficStats.getTotalRxBytes();
long receivedBytes = receivedBytesAfter - receivedBytesBefore;
最后Android开发网再次提醒开发者,TrafficStats类工作在Android 2.2 API Level为8的固件上。
更多相关文章
- Android(安卓)This text field does not specify an inputType o
- Android(安卓)RoboGuice 使用指南(4):Linked Bindings
- android 性能检测资料合集
- Android在标准linux基础上对休眠唤醒的实现(二)
- Android跨进程数据通讯-剪切板Clipboard
- [置顶] Android(安卓)设置铃声分析
- Android(安卓)okHttp 实战(三):okHttp网络请求之Json解析
- 安卓文件读写操作方法汇总
- Android在标准linux基础上对休眠唤醒的实现