# NetworkStats.Bucket

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

# NetworkStats.Bucket

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/app/usage/NetworkStats.Bucket "View this page in Kotlin")\|Java

`
public
static


class
NetworkStats.Bucket
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|---------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.usage.NetworkStats.Bucket |

<br />

*** ** * ** ***

Buckets are the smallest elements of a query result. As some dimensions of a result may be aggregated (e.g. time or state) some values may be equal across all buckets.

## Summary

|                                                                                             ### Constants                                                                                             ||
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [DEFAULT_NETWORK_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_ALL) Combined usage for this network regardless of default network status. |
| `int` | [DEFAULT_NETWORK_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_NO) Usage that occurs while this network is not a default network.          |
| `int` | [DEFAULT_NETWORK_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_YES) Usage that occurs while this network is a default network.            |
| `int` | [METERED_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL) Combined usage across all metered states.                                             |
| `int` | [METERED_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_NO) Usage that occurs on an unmetered network.                                              |
| `int` | [METERED_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_YES) Usage that occurs on a metered network.                                               |
| `int` | [ROAMING_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL) Combined usage across all roaming states.                                             |
| `int` | [ROAMING_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_NO) Usage that occurs on a home, non-roaming network.                                       |
| `int` | [ROAMING_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_YES) Usage that occurs on a roaming network.                                               |
| `int` | [STATE_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_ALL) Combined usage across all states.                                                         |
| `int` | [STATE_DEFAULT](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_DEFAULT) Usage not accounted for in any other state.                                       |
| `int` | [STATE_FOREGROUND](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_FOREGROUND) Foreground usage.                                                           |
| `int` | [TAG_NONE](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#TAG_NONE) Special TAG value for total data across all tags                                            |
| `int` | [UID_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#UID_ALL) Special UID value for aggregate/unspecified.                                                  |
| `int` | [UID_REMOVED](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#UID_REMOVED) Special UID value for removed apps.                                                   |
| `int` | [UID_TETHERING](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#UID_TETHERING) Special UID value for data usage by tethering.                                    |

|                                           ### Public constructors                                           ||
|----------------------------------------------------------------------------------------------------------|---|
| ` `[Bucket](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#Bucket())`() ` |

|                                                                                       ### Public methods                                                                                       ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` int`  | ` `[getDefaultNetworkStatus](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getDefaultNetworkStatus())`() ` Default network status.                    |
| ` long` | ` `[getEndTimeStamp](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getEndTimeStamp())`() ` End timestamp of the bucket's time interval.               |
| ` int`  | ` `[getMetered](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getMetered())`() ` Metered state.                                                       |
| ` int`  | ` `[getRoaming](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getRoaming())`() ` Roaming state.                                                       |
| ` long` | ` `[getRxBytes](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getRxBytes())`() ` Number of bytes received during the bucket's time interval.          |
| ` long` | ` `[getRxPackets](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getRxPackets())`() ` Number of packets received during the bucket's time interval.    |
| ` long` | ` `[getStartTimeStamp](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getStartTimeStamp())`() ` Start timestamp of the bucket's time interval.         |
| ` int`  | ` `[getState](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getState())`() ` Usage state.                                                             |
| ` int`  | ` `[getTag](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getTag())`() ` Tag of the bucket.                                                           |
| ` long` | ` `[getTxBytes](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getTxBytes())`() ` Number of bytes transmitted during the bucket's time interval.       |
| ` long` | ` `[getTxPackets](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getTxPackets())`() ` Number of packets transmitted during the bucket's time interval. |
| ` int`  | ` `[getUid](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#getUid())`() ` Key of the bucket.                                                           |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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

### DEFAULT_NETWORK_ALL

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

```
public static final int DEFAULT_NETWORK_ALL
```

Combined usage for this network regardless of default network status.

<br />

Constant Value: -1 (0xffffffff)  

### DEFAULT_NETWORK_NO

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

```
public static final int DEFAULT_NETWORK_NO
```

Usage that occurs while this network is not a default network.

This implies that the app responsible for this usage requested that it occur on a specific network different from the one(s) the system would have selected for it.

<br />

Constant Value: 1 (0x00000001)  

### DEFAULT_NETWORK_YES

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

```
public static final int DEFAULT_NETWORK_YES
```

Usage that occurs while this network is a default network.

This implies that the app either did not select a specific network for this usage, or it selected a network that the system could have selected for app traffic.

<br />

Constant Value: 2 (0x00000002)  

### METERED_ALL

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

```
public static final int METERED_ALL
```

Combined usage across all metered states. Covers metered and unmetered usage.

<br />

Constant Value: -1 (0xffffffff)  

### METERED_NO

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

```
public static final int METERED_NO
```

Usage that occurs on an unmetered network.

<br />

Constant Value: 1 (0x00000001)  

### METERED_YES

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

```
public static final int METERED_YES
```

Usage that occurs on a metered network.

A network is classified as metered when the user is sensitive to heavy data usage on that connection.

<br />

Constant Value: 2 (0x00000002)  

### ROAMING_ALL

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

```
public static final int ROAMING_ALL
```

Combined usage across all roaming states. Covers both roaming and non-roaming usage.

<br />

Constant Value: -1 (0xffffffff)  

### ROAMING_NO

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

```
public static final int ROAMING_NO
```

Usage that occurs on a home, non-roaming network.

Any cellular usage in this bucket was incurred while the device was connected to a tower owned or operated by the user's wireless carrier, or a tower that the user's wireless carrier has indicated should be treated as a home network regardless.

This is also the default value for network types that do not support roaming.

<br />

Constant Value: 1 (0x00000001)  

### ROAMING_YES

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

```
public static final int ROAMING_YES
```

Usage that occurs on a roaming network.

Any cellular usage in this bucket as incurred while the device was roaming on another carrier's network, for which additional charges may apply.

<br />

Constant Value: 2 (0x00000002)  

### STATE_ALL

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

```
public static final int STATE_ALL
```

Combined usage across all states.

<br />

Constant Value: -1 (0xffffffff)  

### STATE_DEFAULT

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

```
public static final int STATE_DEFAULT
```

Usage not accounted for in any other state.

<br />

Constant Value: 1 (0x00000001)  

### STATE_FOREGROUND

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

```
public static final int STATE_FOREGROUND
```

Foreground usage.

<br />

Constant Value: 2 (0x00000002)  

### TAG_NONE

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

```
public static final int TAG_NONE
```

Special TAG value for total data across all tags

<br />

Constant Value: 0 (0x00000000)  

### UID_ALL

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

```
public static final int UID_ALL
```

Special UID value for aggregate/unspecified.

<br />

Constant Value: -1 (0xffffffff)  

### UID_REMOVED

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

```
public static final int UID_REMOVED
```

Special UID value for removed apps.

<br />

Constant Value: -4 (0xfffffffc)  

### UID_TETHERING

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

```
public static final int UID_TETHERING
```

Special UID value for data usage by tethering.

<br />

Constant Value: -5 (0xfffffffb)

## Public constructors

### Bucket

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

```
public Bucket ()
```

<br />

<br />

## Public methods

### getDefaultNetworkStatus

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

```
public int getDefaultNetworkStatus ()
```

Default network status. One of the following values:

<br />

- [DEFAULT_NETWORK_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_ALL)
- [DEFAULT_NETWORK_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_NO)
- [DEFAULT_NETWORK_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_YES)

<br />

<br />

|                                                                                                                                                                                              Returns                                                                                                                                                                                              ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | Value is[DEFAULT_NETWORK_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_ALL),[DEFAULT_NETWORK_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_NO), or[DEFAULT_NETWORK_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_YES) <br /> |

### getEndTimeStamp

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

```
public long getEndTimeStamp ()
```

End timestamp of the bucket's time interval. Defined in terms of "Unix time", see[System.currentTimeMillis()](https://developer.android.com/reference/java/lang/System#currentTimeMillis()).

<br />

|             Returns             ||
|--------|-------------------------|
| `long` | End of interval. <br /> |

### getMetered

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

```
public int getMetered ()
```

Metered state. One of the following values:

<br />

- [METERED_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL)
- [METERED_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_NO)
- [METERED_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_YES)

A network is classified as metered when the user is sensitive to heavy data usage on that connection. Apps may warn before using these networks for large downloads. The metered state can be set by the user within data usage network restrictions.

<br />

|                                                                                                                                                                      Returns                                                                                                                                                                      ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | Value is[METERED_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL),[METERED_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_NO), or[METERED_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_YES) <br /> |

### getRoaming

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

```
public int getRoaming ()
```

Roaming state. One of the following values:

<br />

- [ROAMING_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL)
- [ROAMING_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_NO)
- [ROAMING_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_YES)

<br />

<br />

|                                                                                                                                                                      Returns                                                                                                                                                                      ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | Value is[ROAMING_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL),[ROAMING_NO](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_NO), or[ROAMING_YES](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_YES) <br /> |

### getRxBytes

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

```
public long getRxBytes ()
```

Number of bytes received during the bucket's time interval. Statistics are measured at the network layer, so they include both TCP and UDP usage.

<br />

|             Returns             ||
|--------|-------------------------|
| `long` | Number of bytes. <br /> |

### getRxPackets

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

```
public long getRxPackets ()
```

Number of packets received during the bucket's time interval. Statistics are measured at the network layer, so they include both TCP and UDP usage.

<br />

|              Returns              ||
|--------|---------------------------|
| `long` | Number of packets. <br /> |

### getStartTimeStamp

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

```
public long getStartTimeStamp ()
```

Start timestamp of the bucket's time interval. Defined in terms of "Unix time", see[System.currentTimeMillis()](https://developer.android.com/reference/java/lang/System#currentTimeMillis()).

<br />

|              Returns              ||
|--------|---------------------------|
| `long` | Start of interval. <br /> |

### getState

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

```
public int getState ()
```

Usage state. One of the following values:

<br />

- [STATE_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_ALL)
- [STATE_DEFAULT](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_DEFAULT)
- [STATE_FOREGROUND](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_FOREGROUND)

<br />

<br />

|                                                                                                                                                                                  Returns                                                                                                                                                                                   ||
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | Usage state. Value is[STATE_ALL](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_ALL),[STATE_DEFAULT](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_DEFAULT), or[STATE_FOREGROUND](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_FOREGROUND) <br /> |

### getTag

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

```
public int getTag ()
```

Tag of the bucket.

<br />

<br />

<br />

|          Returns          ||
|-------|--------------------|
| `int` | Bucket tag. <br /> |

### getTxBytes

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

```
public long getTxBytes ()
```

Number of bytes transmitted during the bucket's time interval. Statistics are measured at the network layer, so they include both TCP and UDP usage.

<br />

|             Returns             ||
|--------|-------------------------|
| `long` | Number of bytes. <br /> |

### getTxPackets

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

```
public long getTxPackets ()
```

Number of packets transmitted during the bucket's time interval. Statistics are measured at the network layer, so they include both TCP and UDP usage.

<br />

|              Returns              ||
|--------|---------------------------|
| `long` | Number of packets. <br /> |

### getUid

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

```
public int getUid ()
```

Key of the bucket. Usually an app uid or one of the following special values:

<br />

- [UID_REMOVED](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#UID_REMOVED)
- [UID_TETHERING](https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#UID_TETHERING)
- [Process.SYSTEM_UID](https://developer.android.com/reference/android/os/Process#SYSTEM_UID)

<br />

<br />

|          Returns          ||
|-------|--------------------|
| `int` | Bucket key. <br /> |