android 笔记 --- 流量统计
16lz
2021-12-04
Android流量统计TrafficStats类的使用
对于Android流量统计来说在2.2版中加入了TrafficStats类可以轻松获取,其实本身TrafficStats类也是读取Linux提供的文件对象系统类型的文本进行解析。android.net.TrafficStats类中,提供了多种静态方法,可以直接调用获取,返回类型均为 long型,如果返回等于-1代表 UNSUPPORTED 当前设备不支持统计。
对于Android流量统计来说在2.2版中加入了TrafficStats类可以轻松获取,其实本身TrafficStats类也是读取Linux提供的文件对象系统类型的文本进行解析。android.net.TrafficStats类中,提供了多种静态方法,可以直接调用获取,返回类型均为 long型,如果返回等于-1代表 UNSUPPORTED 当前设备不支持统计。
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的发送字节数
更多相关文章
- 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
- android根据uri或文件绝对路径获取文件基本信息
- Android中使用ViewPager制作广告栏滚屏效果
- android EditText 取消自动获取焦点
- android 线程中的ui问题 Handler的基本使用 关于获取动态时间在u
- 获取Android(安卓)SDK 源代码并在Eclipse中关联查看的方法
- android UI线程向子线程发送Message
- Android(安卓)下使用 JSON 实现 HTTP 请求,外加几个示例!
- Android关于短信加密