最近做个需求要在native层的某个应用中加入流量统计,所以研究了一下Android自带的流量统计代码,将JNI中的代码直接移植到了我需要的地方
Android提供的流量统计功能在TrafficStats.java类中,包含以下几个:
- public static long getMobileTxPackets() //Return number of packets transmitted across mobile networks since device boot
- public static long getMobileRxPackets() //Return number of packets received across mobile networks since device boot
- public static long getMobileTxBytes() //Return number of bytes transmitted across mobile networks since device boot
- public static long getMobileRxBytes() //Return number of bytes received across mobile networks since device boot
- public static long getMobileTcpRxPackets() //tcp received
- public static long getMobileTcpTxPackets() //tcp transmitted
- public static long getTotalTxPackets //Return number of packets transmitted since device boot
- public static long getTotalRxPackets() //Return number of packets received since device boot
- public static long getTotalTxBytes() //Return number of bytes transmitted since device boot
- public static long getTotalRxBytes() //Return number of bytes received since device boot