# TrafficStatsCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1  
Summary:[Methods](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#)  

# TrafficStatsCompat

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
TrafficStatsCompat
`  
`

extends Object


``


`

|---|-------------------------------------------|
| java.lang.Object                             ||
| ↳ | android.support.v4.net.TrafficStatsCompat |

<br />

*** ** * ** ***

Helper for accessing features in[TrafficStats](https://developer.android.com/reference/android/net/TrafficStats.html).

## Summary

|                                                                                                                                                                                              ### Public methods                                                                                                                                                                                              ||
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static void` | ` `[clearThreadStatsTag](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#clearThreadStatsTag())`() ` *This method was deprecated in API level 26.1.0. Use[clearThreadStatsTag()](https://developer.android.com/reference/android/net/TrafficStats.html#clearThreadStatsTag())directly.*                                                                    |
| ` static int`  | ` `[getThreadStatsTag](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#getThreadStatsTag())`() ` *This method was deprecated in API level 26.1.0. Use[getThreadStatsTag()](https://developer.android.com/reference/android/net/TrafficStats.html#getThreadStatsTag())directly.*                                                                            |
| ` static void` | ` `[incrementOperationCount](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#incrementOperationCount(int))`(int operationCount) ` *This method was deprecated in API level 26.1.0. Use[incrementOperationCount(int)](https://developer.android.com/reference/android/net/TrafficStats.html#incrementOperationCount(int))directly.*                         |
| ` static void` | ` `[incrementOperationCount](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#incrementOperationCount(int, int))`(int tag, int operationCount) ` *This method was deprecated in API level 26.1.0. Use[incrementOperationCount(int, int)](https://developer.android.com/reference/android/net/TrafficStats.html#incrementOperationCount(int, int))directly.* |
| ` static void` | ` `[setThreadStatsTag](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#setThreadStatsTag(int))`(int tag) ` *This method was deprecated in API level 26.1.0. Use[setThreadStatsTag(int)](https://developer.android.com/reference/android/net/TrafficStats.html#setThreadStatsTag(int))directly.*                                                            |
| ` static void` | ` `[tagDatagramSocket](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#tagDatagramSocket(java.net.DatagramSocket))`(DatagramSocket socket) ` Tag the given[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket)with any statistics parameters active for the current thread.                                                   |
| ` static void` | ` `[tagSocket](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#tagSocket(java.net.Socket))`(Socket socket) ` *This method was deprecated in API level 26.1.0. Use[tagSocket(Socket)](https://developer.android.com/reference/android/net/TrafficStats.html#tagSocket(java.net.Socket))directly.*                                                           |
| ` static void` | ` `[untagDatagramSocket](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#untagDatagramSocket(java.net.DatagramSocket))`(DatagramSocket socket) ` Remove any statistics parameters from the given[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket).                                                                         |
| ` static void` | ` `[untagSocket](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#untagSocket(java.net.Socket))`(Socket socket) ` *This method was deprecated in API level 26.1.0. Use[untagSocket(Socket)](https://developer.android.com/reference/android/net/TrafficStats.html#untagSocket(java.net.Socket))directly.*                                                   |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public methods

### clearThreadStatsTag

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void clearThreadStatsTag ()
```

<br />

**This method was deprecated in API level 26.1.0.**   
Use[clearThreadStatsTag()](https://developer.android.com/reference/android/net/TrafficStats.html#clearThreadStatsTag())directly.

Clear active tag used when accounting[Socket](https://developer.android.com/reference/java/net/Socket)traffic originating from the current thread.

<br />

### getThreadStatsTag

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getThreadStatsTag ()
```

<br />

**This method was deprecated in API level 26.1.0.**   
Use[getThreadStatsTag()](https://developer.android.com/reference/android/net/TrafficStats.html#getThreadStatsTag())directly.

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

<br />

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

### incrementOperationCount

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void incrementOperationCount (int operationCount)
```

<br />

**This method was deprecated in API level 26.1.0.**   
Use[incrementOperationCount(int)](https://developer.android.com/reference/android/net/TrafficStats.html#incrementOperationCount(int))directly.

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[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

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

<br />

**This method was deprecated in API level 26.1.0.**   
Use[incrementOperationCount(int, int)](https://developer.android.com/reference/android/net/TrafficStats.html#incrementOperationCount(int, int))directly.

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[setThreadStatsTag(int)](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#setThreadStatsTag(int)). <br /> |
| `operationCount` | `int`: Number of operations to increment count by. <br />                                                                                                               |

### setThreadStatsTag

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setThreadStatsTag (int tag)
```

<br />

**This method was deprecated in API level 26.1.0.**   
Use[setThreadStatsTag(int)](https://developer.android.com/reference/android/net/TrafficStats.html#setThreadStatsTag(int))directly.

Set active tag to use when accounting[Socket](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[tagSocket(Socket)](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#tagSocket(java.net.Socket)).

Tags between`0xFFFFFF00`and`0xFFFFFFFF`are reserved and used internally by system services like DownloadManager when performing traffic on behalf of an application.

<br />

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

### tagDatagramSocket

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void tagDatagramSocket (DatagramSocket socket)
```

Tag the given[DatagramSocket](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[untagDatagramSocket(DatagramSocket)](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#untagDatagramSocket(java.net.DatagramSocket))to remove statistics parameters.

<br />

|            Parameters             ||
|----------|-------------------------|
| `socket` | `DatagramSocket` <br /> |

|        Throws        ||
|-------------------|---|
| `SocketException` |   |

**See also:**

- [setThreadStatsTag(int)](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#setThreadStatsTag(int))  

### tagSocket

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void tagSocket (Socket socket)
```

<br />

**This method was deprecated in API level 26.1.0.**   
Use[tagSocket(Socket)](https://developer.android.com/reference/android/net/TrafficStats.html#tagSocket(java.net.Socket))directly.

Tag the given[Socket](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[untagSocket(Socket)](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#untagSocket(java.net.Socket))to remove statistics parameters.

<br />

|        Parameters         ||
|----------|-----------------|
| `socket` | `Socket` <br /> |

|        Throws        ||
|-------------------|---|
| `SocketException` |   |

**See also:**

- [setThreadStatsTag(int)](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat#setThreadStatsTag(int))  

### untagDatagramSocket

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void untagDatagramSocket (DatagramSocket socket)
```

Remove any statistics parameters from the given[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket).

<br />

|            Parameters             ||
|----------|-------------------------|
| `socket` | `DatagramSocket` <br /> |

|        Throws        ||
|-------------------|---|
| `SocketException` |   |

### untagSocket

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void untagSocket (Socket socket)
```

<br />

**This method was deprecated in API level 26.1.0.**   
Use[untagSocket(Socket)](https://developer.android.com/reference/android/net/TrafficStats.html#untagSocket(java.net.Socket))directly.

Remove any statistics parameters from the given[Socket](https://developer.android.com/reference/java/net/Socket).

<br />

|        Parameters         ||
|----------|-----------------|
| `socket` | `Socket` <br /> |

|        Throws        ||
|-------------------|---|
| `SocketException` |   |

-

  ## Classes

  - [ConnectivityManagerCompat](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat)
  - [TrafficStatsCompat](https://developer.android.com/reference/android/support/v4/net/TrafficStatsCompat)