android 流量统计
来源:互联网 发布:电脑小白编程软件 编辑:程序博客网 时间:2024/05/29 10:23
对于Android流量统计来说在2.2版中新加入了TrafficStats类可以轻松获取,其实本身TrafficStats类也是读取Linux提供的文件对象系统类型的文本进行解析。android.net.TrafficStats类中,提供了多种静态方法,可以直接调用获取,返回类型均为 long型,如果返回等于-1代表 UNSUPPORTED 当前设备不支持统计。
总接受流量TrafficStats.getTotalRxBytes(),
总发送流量TrafficStats.getTotalTxBytes());
不包含WIFI的手机GPRS接收量TrafficStats.getMobileRxBytes());
不包含Wifi的手机GPRS发送量TrafficStats.getMobileTxBytes());
某一个进程的总接收量TrafficStats.getUidRxBytes(Uid));
某一个进程的总发送量TrafficStats.getUidTxBytes(Uid));
这些都是从第一次启动程序到最后一次启动的统计量。并不是这篇文章里所说的“从本次开机到本次关机的统计量”!
用法举例,注意这里得到的单位都是"KB"
- static long getMobileRxBytes() //获取通过Mobile连接收到的字节总数,不包含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的发送字节数
总接受流量TrafficStats.getTotalRxBytes(),
总发送流量TrafficStats.getTotalTxBytes());
不包含WIFI的手机GPRS接收量TrafficStats.getMobileRxBytes());
不包含Wifi的手机GPRS发送量TrafficStats.getMobileTxBytes());
某一个进程的总接收量TrafficStats.getUidRxBytes(Uid));
某一个进程的总发送量TrafficStats.getUidTxBytes(Uid));
这些都是从第一次启动程序到最后一次启动的统计量。并不是这篇文章里所说的“从本次开机到本次关机的统计量”!
用法举例,注意这里得到的单位都是"KB"
- public long getTotalRxBytes(){ //获取总的接受字节数,包含Mobile和WiFi等
- return TrafficStats.getTotalRxBytes()==TrafficStats.UNSUPPORTED?0:(TrafficStats.getTotalRxBytes()/1024);
- }
- public long getTotalTxBytes(){ //总的发送字节数,包含Mobile和WiFi等
- return TrafficStats.getTotalTxBytes()==TrafficStats.UNSUPPORTED?0:(TrafficStats.getTotalTxBytes()/1024);
- }
- public long getMobileRxBytes(){ //获取通过Mobile连接收到的字节总数,不包含WiFi
- return TrafficStats.getMobileRxBytes()==TrafficStats.UNSUPPORTED?0:(TrafficStats.getMobileRxBytes()/1024);
- }
0 0
- android流量统计
- android 流量统计
- Android流量统计代码
- android流量统计
- 关于android流量统计
- android流量统计
- Android统计流量 代码
- Android流量统计
- Android流量统计
- android 流量的统计
- android 流量的统计
- android 流量统计
- android流量统计
- android App流量统计
- android 数据流量统计
- android流量统计
- Android流量统计知识点
- Android TrafficStats流量统计
- Effective Scala
- memcpy
- Win7 64位下PowerDesigner连接64位Oracle11g数据库
- Qt4 和 Qt5 模块的分类
- Linux那些事儿之我是Sysfs(11)sysfs 创建普通文件
- android 流量统计
- 【CF 675D】 Tree Construction(离线二分+左右指针)
- Scala 课堂!
- [转]Innodb index
- Ibatis自我关联
- 形、音、义的纠葛——《语文常谈》读书笔记(3)
- 微信支付集锦
- 深入JVM内核
- scanf 用法及陷阱(转)