Method for obtaining traffic-related data in Android

TrafficStats tools are mainly used to obtain traffic-related data. Here are the main methods of this class.

  • getTotalRxBytes: Get the total number of bytes of received traffic.
  • getTotalTxBytes: Get the total number of bytes of sent traffic.
  • getMobileRxBytes: Get the total number of bytes of data connection received traffic, including mobile data traffic, excluding wifi traffic.
  • getMobileTxBytes: Gets the total number of bytes of data connection sent traffic.
  • getUidRxBytes: Get the total number of bytes of traffic received by the specified process.
  • getUidTxBytes: Get the total bytes of traffic sent by the specified process.

It should be noted that after Android7, the getUidRxBytes and getUidTxBytes of the TrafficStats class can only check their own traffic. Only when the current application is a system application, can the traffic of other applications be checked.

Guess you like

Origin blog.csdn.net/weixin_38322371/article/details/114025361