/**
* Return number of packets transmitted since device boot. Counts packets
* across all network interfaces, and always increases monotonically since
* device boot. Statistics are measured at the network layer, so they
* include both TCP and UDP usage.
*/
public static long getTotalTxPackets()
/**
* Return number of packets received since device boot. Counts packets
* across all network interfaces, and always increases monotonically since
* device boot. Statistics are measured at the network layer, so they
* include both TCP and UDP usage.
*/
public static long getTotalRxPackets()
/**
* Return number of bytes transmitted since device boot. Counts packets
* across all network interfaces, and always increases monotonically since
* device boot. Statistics are measured at the network layer, so they
* include both TCP and UDP usage.
*/
public static long getTotalTxBytes()
/**
* Return number of bytes received since device boot. Counts packets across
* all network interfaces, and always increases monotonically since device
* boot. Statistics are measured at the network layer, so they include both
* TCP and UDP usage.
*/
public static long getTotalRxBytes()
2 统计移动网络流量
/**
* Return number of packets transmitted across mobile networks since device
* boot. Counts packets across all mobile network interfaces, and always
* increases monotonically since device boot. Statistics are measured at the
* network layer, so they include both TCP and UDP usage.
*/
public static long getMobileTxPackets()
/**
* Return number of packets received across mobile networks since device
* boot. Counts packets across all mobile network interfaces, and always
* increases monotonically since device boot. Statistics are measured at the
* network layer, so they include both TCP and UDP usage.
*/
public static long getMobileRxPackets()
/**
* Return number of bytes transmitted across mobile networks since device
* boot. Counts packets across all mobile network interfaces, and always
* increases monotonically since device boot. Statistics are measured at the
* network layer, so they include both TCP and UDP usage.
*/
public static long getMobileTxBytes()
/**
* Return number of bytes received across mobile networks since device boot.
* Counts packets across all mobile network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
*/
public static long getMobileRxBytes()
3 按接口统计流量
/**
* Return the number of packets transmitted on the specified interface since the interface
* was created. Statistics are measured at the network layer, so both TCP and
* UDP usage are included.
*
* Note that the returned values are partial statistics that do not count data from several
* sources and do not apply several adjustments that are necessary for correctness, such
* as adjusting for VPN apps, IPv6-in-IPv4 translation, etc. These values can be used to
* determine whether traffic is being transferred on the specific interface but are not a
* substitute for the more accurate statistics provided by the {@link NetworkStatsManager}
* APIs.
*/
public static long getTxPackets(@NonNull String iface)
/**
* Return the number of packets received on the specified interface since the interface was
* created. Statistics are measured at the network layer, so both TCP
* and UDP usage are included.
*
* Note that the returned values are partial statistics that do not count data from several
* sources and do not apply several adjustments that are necessary for correctness, such
* as adjusting for VPN apps, IPv6-in-IPv4 translation, etc. These values can be used to
* determine whether traffic is being transferred on the specific interface but are not a
* substitute for the more accurate statistics provided by the {@link NetworkStatsManager}
* APIs.
*/
public static long getRxPackets(@NonNull String iface)
/**
* Return the number of bytes transmitted on the specified interface since the interface
* was created. Statistics are measured at the network layer, so both TCP and
* UDP usage are included.
*
* Note that the returned values are partial statistics that do not count data from several
* sources and do not apply several adjustments that are necessary for correctness, such
* as adjusting for VPN apps, IPv6-in-IPv4 translation, etc. These values can be used to
* determine whether traffic is being transferred on the specific interface but are not a
* substitute for the more accurate statistics provided by the {@link NetworkStatsManager}
* APIs.
*/
public static long getTxBytes(@NonNull String iface)
/**
* Return the number of bytes received on the specified interface since the interface
* was created. Statistics are measured at the network layer, so both TCP
* and UDP usage are included.
*
* Note that the returned values are partial statistics that do not count data from several
* sources and do not apply several adjustments that are necessary for correctness, such
* as adjusting for VPN apps, IPv6-in-IPv4 translation, etc. These values can be used to
* determine whether traffic is being transferred on the specific interface but are not a
* substitute for the more accurate statistics provided by the {@link NetworkStatsManager}
* APIs.
*/
public static long getRxBytes(@NonNull String iface)
4 按UID统计流量
/**
* Return number of bytes transmitted by the given UID since device boot.
* Counts packets across all network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
*/
public static long getUidTxBytes(int uid)
/**
* Return number of bytes received by the given UID since device boot.
* Counts packets across all network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
*/
public static long getUidRxBytes(int uid)
/**
* Return number of packets transmitted by the given UID since device boot.
* Counts packets across all network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
*/
public static long getUidTxPackets(int uid)
/**
* Return number of packets received by the given UID since device boot.
* Counts packets across all network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
*/
public static long getUidRxPackets(int uid)
5 按时间段统计流量
/**
* Query network usage statistics summaries. Result is summarised data usage for the whole
* device. Result is a single Bucket aggregated over time, state, uid, tag, metered, and
* roaming. This means the bucket's start and end timestamp are going to be the same as the
* 'startTime' and 'endTime' parameters. State is going to be
* {@link NetworkStats.Bucket#STATE_ALL}, uid {@link NetworkStats.Bucket#UID_ALL},
* tag {@li