public class

TrafficStats

extends Object
java.lang.Object
   ↳ android.net.TrafficStats

Class Overview

Class that provides network traffic statistics. These statistics include bytes transmitted and received and network packets transmitted and received, over all interfaces, over the mobile interface, and on a per-UID basis.

These statistics may not be available on all platforms. If the statistics are not supported by this device, UNSUPPORTED will be returned.

Summary

Constants
int UNSUPPORTED The return value to indicate that the device does not support the statistic.
Public Constructors
TrafficStats()
Public Methods
static long getMobileRxBytes()
Get the total number of bytes received through the mobile interface.
static long getMobileRxPackets()
Get the total number of packets received through the mobile interface.
static long getMobileTxBytes()
Get the total number of bytes transmitted through the mobile interface.
static long getMobileTxPackets()
Get the total number of packets transmitted through the mobile interface.
static long getTotalRxBytes()
Get the total number of bytes received through all network interfaces.
static long getTotalRxPackets()
Get the total number of packets received through all network interfaces.
static long getTotalTxBytes()
Get the total number of bytes sent through all network interfaces.
static long getTotalTxPackets()
Get the total number of packets sent through all network interfaces.
static long getUidRxBytes(int uid)
Get the number of bytes received through the network for this UID.
static long getUidTxBytes(int uid)
Get the number of bytes sent through the network for this UID.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int UNSUPPORTED

Since: API Level 8

The return value to indicate that the device does not support the statistic.

Constant Value: -1 (0xffffffff)

Public Constructors

public TrafficStats ()

Since: API Level 8

Public Methods

public static long getMobileRxBytes ()

Since: API Level 8

Get the total number of bytes received through the mobile interface.

Returns
  • number of bytes. If the statistics are not supported by this device, UNSUPPORTED will be returned.

public static long getMobileRxPackets ()

Since: API Level 8

Get the total number of packets received through the mobile interface.

Returns
  • number of packets. If the statistics are not supported by this device, UNSUPPORTED will be returned.

public static long getMobileTxBytes ()

Since: API Level 8

Get the total number of bytes transmitted through the mobile interface.

Returns
  • number of bytes. If the statistics are not supported by this device, UNSUPPORTED will be returned.

public static long getMobileTxPackets ()

Since: API Level 8

Get the total number of packets transmitted through the mobile interface.

Returns
  • number of packets. If the statistics are not supported by this device, UNSUPPORTED will be returned.

public static long getTotalRxBytes ()

Since: API Level 8

Get the total number of bytes received through all network interfaces.

Returns
  • number of bytes. If the statistics are not supported by this device, UNSUPPORTED will be returned.

public static long getTotalRxPackets ()

Since: API Level 8

Get the total number of packets received through all network interfaces.

Returns
  • number of packets. If the statistics are not supported by this device, UNSUPPORTED will be returned.

public static long getTotalTxBytes ()

Since: API Level 8

Get the total number of bytes sent through all network interfaces.

Returns
  • number of bytes. If the statistics are not supported by this device, UNSUPPORTED will be returned.

public static long getTotalTxPackets ()

Since: API Level 8

Get the total number of packets sent through all network interfaces.

Returns
  • the number of packets. If the statistics are not supported by this device, UNSUPPORTED will be returned.

public static long getUidRxBytes (int uid)

Since: API Level 8

Get the number of bytes received through the network for this UID. The statistics are across all interfaces. .

Parameters
uid The UID of the process to examine.
Returns
  • number of bytes
See Also

public static long getUidTxBytes (int uid)

Since: API Level 8

Get the number of bytes sent through the network for this UID. The statistics are across all interfaces. .

Parameters
uid The UID of the process to examine.
Returns
  • number of bytes. If the statistics are not supported by this device, UNSUPPORTED will be returned.
See Also