Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/net/TrafficStats#constants) \| [Ctors](https://developer.android.com/reference/android/net/TrafficStats#pubctors) \| [Methods](https://developer.android.com/reference/android/net/TrafficStats#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/TrafficStats#inhmethods)

# TrafficStats

*** ** * ** ***

` public class TrafficStats `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.TrafficStats |

<br />

*** ** * ** ***

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, `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` will be returned.

Note that the statistics returned by this class reset and start from zero after every reboot. To access more robust historical network statistics data, use `https://developer.android.com/reference/android/app/usage/NetworkStatsManager` instead.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` The return value to indicate that the device does not support the statistic. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/net/TrafficStats#TrafficStats()() ` |

| ### Public methods ||
|---|---|
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#clearThreadStatsTag()() ` Clear any active tag set to account `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#clearThreadStatsUid()() ` Clear any active UID set to account `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. |
| ` static int` | ` https://developer.android.com/reference/android/net/TrafficStats#getAndSetThreadStatsTag(int)(int tag) ` Set active tag to use when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getMobileRxBytes()() ` Return number of bytes received across mobile networks since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getMobileRxPackets()() ` Return number of packets received across mobile networks since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getMobileTxBytes()() ` Return number of bytes transmitted across mobile networks since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getMobileTxPackets()() ` Return number of packets transmitted across mobile networks since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getRxBytes(java.lang.String)(https://developer.android.com/reference/java/lang/String iface) ` Return the number of bytes received on the specified interface since the interface was created. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getRxPackets(java.lang.String)(https://developer.android.com/reference/java/lang/String iface) ` Return the number of packets received on the specified interface since the interface was created. |
| ` static int` | ` https://developer.android.com/reference/android/net/TrafficStats#getThreadStatsTag()() ` Get the active tag used when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. |
| ` static int` | ` https://developer.android.com/reference/android/net/TrafficStats#getThreadStatsUid()() ` Get the active UID used when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getTotalRxBytes()() ` Return number of bytes received since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getTotalRxPackets()() ` Return number of packets received since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getTotalTxBytes()() ` Return number of bytes transmitted since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getTotalTxPackets()() ` Return number of packets transmitted since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getTxBytes(java.lang.String)(https://developer.android.com/reference/java/lang/String iface) ` Return the number of bytes transmitted on the specified interface since the interface was created. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getTxPackets(java.lang.String)(https://developer.android.com/reference/java/lang/String iface) ` Return the number of packets transmitted on the specified interface since the interface was created. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidRxBytes(int)(int uid) ` Return number of bytes received by the given UID since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidRxPackets(int)(int uid) ` Return number of packets received by the given UID since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidTcpRxBytes(int)(int uid) ` *This method was deprecated in API level 18. Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.* |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidTcpRxSegments(int)(int uid) ` *This method was deprecated in API level 18. Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.* |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidTcpTxBytes(int)(int uid) ` *This method was deprecated in API level 18. Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.* |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidTcpTxSegments(int)(int uid) ` *This method was deprecated in API level 18. Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.* |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidTxBytes(int)(int uid) ` Return number of bytes transmitted by the given UID since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidTxPackets(int)(int uid) ` Return number of packets transmitted by the given UID since device boot. |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidUdpRxBytes(int)(int uid) ` *This method was deprecated in API level 18. Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.* |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidUdpRxPackets(int)(int uid) ` *This method was deprecated in API level 18. Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.* |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidUdpTxBytes(int)(int uid) ` *This method was deprecated in API level 18. Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.* |
| ` static long` | ` https://developer.android.com/reference/android/net/TrafficStats#getUidUdpTxPackets(int)(int uid) ` *This method was deprecated in API level 18. Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.* |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#incrementOperationCount(int)(int operationCount) ` Increment count of network operations performed under the accounting tag currently active on the calling thread. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#incrementOperationCount(int,%20int)(int tag, int operationCount) ` Increment count of network operations performed under the given accounting tag. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsTag(int)(int tag) ` Set active tag to use when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsUid(int)(int uid) ` Set specific UID to use when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#tagDatagramSocket(java.net.DatagramSocket)(https://developer.android.com/reference/java/net/DatagramSocket socket) ` Tag the given `https://developer.android.com/reference/java/net/DatagramSocket` with any statistics parameters active for the current thread. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#tagFileDescriptor(java.io.FileDescriptor)(https://developer.android.com/reference/java/io/FileDescriptor fd) ` Tag the given `https://developer.android.com/reference/java/io/FileDescriptor` socket with any statistics parameters active for the current thread. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#tagSocket(java.net.Socket)(https://developer.android.com/reference/java/net/Socket socket) ` Tag the given `https://developer.android.com/reference/java/net/Socket` with any statistics parameters active for the current thread. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#untagDatagramSocket(java.net.DatagramSocket)(https://developer.android.com/reference/java/net/DatagramSocket socket) ` Remove any statistics parameters from the given `https://developer.android.com/reference/java/net/DatagramSocket`. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#untagFileDescriptor(java.io.FileDescriptor)(https://developer.android.com/reference/java/io/FileDescriptor fd) ` Remove any statistics parameters from the given `https://developer.android.com/reference/java/io/FileDescriptor` socket. |
| ` static void` | ` https://developer.android.com/reference/android/net/TrafficStats#untagSocket(java.net.Socket)(https://developer.android.com/reference/java/net/Socket socket) ` Remove any statistics parameters from the given `https://developer.android.com/reference/java/net/Socket`. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### UNSUPPORTED

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int UNSUPPORTED
```

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

<br />

Constant Value: -1 (0xffffffff)

## Public constructors

### TrafficStats

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public TrafficStats ()
```

<br />

<br />

## Public methods

### clearThreadStatsTag

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void clearThreadStatsTag ()
```

Clear any active tag set to account `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread.

<br />

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsTag(int)`

### clearThreadStatsUid

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void clearThreadStatsUid ()
```

Clear any active UID set to account `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread.

<br />

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsUid(int)`

### getAndSetThreadStatsTag

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int getAndSetThreadStatsTag (int tag)
```

Set active tag to use when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. Only one active tag per thread is supported.

Changes only take effect during subsequent calls to `https://developer.android.com/reference/android/net/TrafficStats#tagSocket(java.net.Socket)`.

Tags between `0xFFFFFF00` and `0xFFFFFFFF` are reserved and used internally by system services like `https://developer.android.com/reference/android/app/DownloadManager` when performing traffic on behalf of an application.

<br />

| Parameters ||
|---|---|
| `tag` | `int` <br /> |

| Returns ||
|---|---|
| `int` | the current tag for the calling thread, which can be used to restore any existing values after a nested operation is finished <br /> |

### getMobileRxBytes

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getMobileRxBytes ()
```

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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getMobileRxPackets

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getMobileRxPackets ()
```

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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getMobileTxBytes

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getMobileTxBytes ()
```

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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getMobileTxPackets

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getMobileTxPackets ()
```

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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getRxBytes

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getRxBytes (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 `https://developer.android.com/reference/android/app/usage/NetworkStatsManager` APIs.

<br />

| Parameters ||
|---|---|
| `iface` | `String`: The name of the interface. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `long` | The number of received bytes. <br /> |

### getRxPackets

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getRxPackets (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 `https://developer.android.com/reference/android/app/usage/NetworkStatsManager` APIs.

<br />

| Parameters ||
|---|---|
| `iface` | `String`: The name of the interface. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `long` | The number of received packets. <br /> |

### getThreadStatsTag

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int getThreadStatsTag ()
```

Get the active tag used when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. Only one active tag per thread is supported. `https://developer.android.com/reference/android/net/TrafficStats#tagSocket(java.net.Socket)`.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsTag(int)`

### getThreadStatsUid

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int getThreadStatsUid ()
```

Get the active UID used when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. Only one active tag per thread is supported. `https://developer.android.com/reference/android/net/TrafficStats#tagSocket(java.net.Socket)`.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsUid(int)`

### getTotalRxBytes

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getTotalRxBytes ()
```

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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getTotalRxPackets

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getTotalRxPackets ()
```

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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getTotalTxBytes

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getTotalTxBytes ()
```

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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getTotalTxPackets

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getTotalTxPackets ()
```

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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getTxBytes

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getTxBytes (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 `https://developer.android.com/reference/android/app/usage/NetworkStatsManager` APIs.

<br />

| Parameters ||
|---|---|
| `iface` | `String`: The name of the interface. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `long` | The number of transmitted bytes. <br /> |

### getTxPackets

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getTxPackets (String iface)
```

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 `https://developer.android.com/reference/android/app/usage/NetworkStatsManager` APIs.

<br />

| Parameters ||
|---|---|
| `iface` | `String`: The name of the interface. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `long` | The number of transmitted packets. <br /> |

### getUidRxBytes

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidRxBytes (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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#N` this will only report traffic statistics for the calling UID. It will return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, use `https://developer.android.com/reference/android/app/usage/NetworkStatsManager`.

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Process#myUid()`
- `https://developer.android.com/reference/android/content/pm/ApplicationInfo#uid`

### getUidRxPackets

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidRxPackets (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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#N` this will only report traffic statistics for the calling UID. It will return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, use `https://developer.android.com/reference/android/app/usage/NetworkStatsManager`.

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Process#myUid()`
- `https://developer.android.com/reference/android/content/pm/ApplicationInfo#uid`

### getUidTcpRxBytes

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidTcpRxBytes (int uid)
```

<br />

**This method was deprecated in API level 18.**   

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.

<br />

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#getUidRxBytes(int)`

### getUidTcpRxSegments

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidTcpRxSegments (int uid)
```

<br />

**This method was deprecated in API level 18.**   

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.

<br />

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#getUidRxPackets(int)`

### getUidTcpTxBytes

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidTcpTxBytes (int uid)
```

<br />

**This method was deprecated in API level 18.**   

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.

<br />

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#getUidTxBytes(int)`

### getUidTcpTxSegments

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidTcpTxSegments (int uid)
```

<br />

**This method was deprecated in API level 18.**   

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.

<br />

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#getUidTxPackets(int)`

### getUidTxBytes

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidTxBytes (int 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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#N` this will only report traffic statistics for the calling UID. It will return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, use `https://developer.android.com/reference/android/app/usage/NetworkStatsManager`.

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Process#myUid()`
- `https://developer.android.com/reference/android/content/pm/ApplicationInfo#uid`

### getUidTxPackets

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidTxPackets (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.

Before `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, this may return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` on devices where statistics aren't available.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#N` this will only report traffic statistics for the calling UID. It will return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED` for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, use `https://developer.android.com/reference/android/app/usage/NetworkStatsManager`.

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/Process#myUid()`
- `https://developer.android.com/reference/android/content/pm/ApplicationInfo#uid`

### getUidUdpRxBytes

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidUdpRxBytes (int uid)
```

<br />

**This method was deprecated in API level 18.**   

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.

<br />

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#getUidRxBytes(int)`

### getUidUdpRxPackets

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidUdpRxPackets (int uid)
```

<br />

**This method was deprecated in API level 18.**   

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.

<br />

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#getUidRxPackets(int)`

### getUidUdpTxBytes

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidUdpTxBytes (int uid)
```

<br />

**This method was deprecated in API level 18.**   

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.

<br />

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#getUidTxBytes(int)`

### getUidUdpTxPackets

Added in [API level 12](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long getUidUdpTxPackets (int uid)
```

<br />

**This method was deprecated in API level 18.**   

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2`, transport layer statistics are no longer available, and will always return `https://developer.android.com/reference/android/net/TrafficStats#UNSUPPORTED`.

<br />

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#getUidTxPackets(int)`

### incrementOperationCount

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void incrementOperationCount (int operationCount)
```

Increment count of network operations performed under the accounting tag currently active on the calling thread. This can be used to derive bytes-per-operation.

<br />

| Parameters ||
|---|---|
| `operationCount` | `int`: Number of operations to increment count by. <br /> |

### incrementOperationCount

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void incrementOperationCount (int tag, 
                int operationCount)
```

Increment count of network operations performed under the given accounting tag. This can be used to derive bytes-per-operation.

<br />

| Parameters ||
|---|---|
| `tag` | `int`: Accounting tag used in `https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsTag(int)`. <br /> |
| `operationCount` | `int`: Number of operations to increment count by. <br /> |

### setThreadStatsTag

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void setThreadStatsTag (int tag)
```

Set active tag to use when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. Only one active tag per thread is supported.

Changes only take effect during subsequent calls to `https://developer.android.com/reference/android/net/TrafficStats#tagSocket(java.net.Socket)`.

Tags between `0xFFFFFF00` and `0xFFFFFFFF` are reserved and used internally by system services like `https://developer.android.com/reference/android/app/DownloadManager` when performing traffic on behalf of an application.

<br />

| Parameters ||
|---|---|
| `tag` | `int` <br /> |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#clearThreadStatsTag()`

### setThreadStatsUid

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void setThreadStatsUid (int uid)
```

Set specific UID to use when accounting `https://developer.android.com/reference/java/net/Socket` traffic originating from the current thread. Designed for use when performing an operation on behalf of another application, or when another application is performing operations on your behalf.

Any app can *accept* blame for traffic performed on a socket originally created by another app by calling this method with the `https://developer.android.com/reference/android/system/Os#getuid()` value. However, only apps holding the `android.Manifest.permission#UPDATE_DEVICE_STATS` permission may *assign* blame to another UIDs.

Changes only take effect during subsequent calls to `https://developer.android.com/reference/android/net/TrafficStats#tagSocket(java.net.Socket)`.

<br />

| Parameters ||
|---|---|
| `uid` | `int` <br /> |

### tagDatagramSocket

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void tagDatagramSocket (DatagramSocket socket)
```

Tag the given `https://developer.android.com/reference/java/net/DatagramSocket` with any statistics parameters active for the current thread. Subsequent calls always replace any existing parameters. When finished, call `https://developer.android.com/reference/android/net/TrafficStats#untagDatagramSocket(java.net.DatagramSocket)` to remove statistics parameters.

<br />

| Parameters ||
|---|---|
| `socket` | `DatagramSocket`: This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/net/SocketException` |   |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsTag(int)`

### tagFileDescriptor

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void tagFileDescriptor (FileDescriptor fd)
```

Tag the given `https://developer.android.com/reference/java/io/FileDescriptor` socket with any statistics parameters active for the current thread. Subsequent calls always replace any existing parameters. When finished, call `https://developer.android.com/reference/android/net/TrafficStats#untagFileDescriptor(java.io.FileDescriptor)` to remove statistics parameters.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsTag(int)`

### tagSocket

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void tagSocket (Socket socket)
```

Tag the given `https://developer.android.com/reference/java/net/Socket` with any statistics parameters active for the current thread. Subsequent calls always replace any existing parameters. When finished, call `https://developer.android.com/reference/android/net/TrafficStats#untagSocket(java.net.Socket)` to remove statistics parameters.

<br />

| Parameters ||
|---|---|
| `socket` | `Socket`: This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/net/SocketException` |   |

**See also:**

- `https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsTag(int)`

### untagDatagramSocket

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void untagDatagramSocket (DatagramSocket socket)
```

Remove any statistics parameters from the given `https://developer.android.com/reference/java/net/DatagramSocket`.

<br />

| Parameters ||
|---|---|
| `socket` | `DatagramSocket`: This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/net/SocketException` |   |

### untagFileDescriptor

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void untagFileDescriptor (FileDescriptor fd)
```

Remove any statistics parameters from the given `https://developer.android.com/reference/java/io/FileDescriptor` socket.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### untagSocket

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void untagSocket (Socket socket)
```

Remove any statistics parameters from the given `https://developer.android.com/reference/java/net/Socket`.

In Android 8.1 (API level 27) and lower, a socket is automatically untagged when it's sent to another process using binder IPC with a `ParcelFileDescriptor` container. In Android 9.0 (API level 28) and higher, the socket tag is kept when the socket is sent to another process using binder IPC. You can mimic the previous behavior by calling `untagSocket()` before sending the socket to another process.

<br />

| Parameters ||
|---|---|
| `socket` | `Socket`: This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/net/SocketException` |   |