Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/app/usage/NetworkStatsManager#nestedclasses) \| [Methods](https://developer.android.com/reference/android/app/usage/NetworkStatsManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/usage/NetworkStatsManager#inhmethods)

# NetworkStatsManager

*** ** * ** ***


`
public


class
NetworkStatsManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

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

<br />

*** ** * ** ***

Provides access to network usage history and statistics. Usage data is collected in
discrete bins of time called 'Buckets'. See `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket` for details.

<br />

Queries can define a time interval in the form of start and end timestamps (Long.MIN_VALUE and Long.MAX_VALUE can be used to simulate open ended intervals). By default, apps can only obtain data about themselves. See the below note for special cases in which apps can obtain data about other applications.

### Summary queries

`https://developer.android.com/reference/android/app/usage/NetworkStatsManager#querySummaryForDevice(int,%20java.lang.String,%20long,%20long)`

<br />

`https://developer.android.com/reference/android/app/usage/NetworkStatsManager#querySummaryForUser(int,%20java.lang.String,%20long,%20long)`

<br />

`https://developer.android.com/reference/android/app/usage/NetworkStatsManager#querySummary(int,%20java.lang.String,%20long,%20long)`

<br />

These queries aggregate network usage across the whole interval. Therefore there will be only one bucket for a particular key, state, metered and roaming combination. In case of the user-wide and device-wide summaries a single bucket containing the totalised network usage is returned.

### History queries

`https://developer.android.com/reference/android/app/usage/NetworkStatsManager#queryDetailsForUid(int,%20java.lang.String,%20long,%20long,%20int)`

<br />

`https://developer.android.com/reference/android/app/usage/NetworkStatsManager#queryDetails(int,%20java.lang.String,%20long,%20long)`

<br />

These queries do not aggregate over time but do aggregate over state, metered and roaming. Therefore there can be multiple buckets for a particular key. However, all Buckets will have `state` `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_ALL`, `defaultNetwork` `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_ALL`, `metered ` `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL`, `roaming` `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL`.

<br />

**NOTE:** Calling `https://developer.android.com/reference/android/app/usage/NetworkStatsManager#querySummaryForDevice(int,%20java.lang.String,%20long,%20long)` or accessing stats for apps other than the calling app requires the permission `https://developer.android.com/reference/android/Manifest.permission#PACKAGE_USAGE_STATS`, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.

<br />

Profile owner apps are automatically granted permission to query data on the profile they manage (that is, for any query except `https://developer.android.com/reference/android/app/usage/NetworkStatsManager#querySummaryForDevice(int,%20java.lang.String,%20long,%20long)`). Device owner apps and carrier- privileged apps likewise get access to usage data for all users on the device.

<br />

In addition to tethering usage, usage by removed users and apps, and usage by the system is also included in the results for callers with one of these higher levels of access.

<br />

**NOTE:** Prior to API level `https://developer.android.com/reference/android/os/Build.VERSION_CODES#N`, all calls to these APIs required the above permission, even to access an app's own data usage, and carrier-privileged apps were not included.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/app/usage/NetworkStatsManager.UsageCallback` Base class for usage callbacks. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/app/usage/NetworkStats` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#queryDetails(int,%20java.lang.String,%20long,%20long)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long startTime, long endTime) ` Query network usage statistics details. |
| ` https://developer.android.com/reference/android/app/usage/NetworkStats` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#queryDetailsForUid(int,%20java.lang.String,%20long,%20long,%20int)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long startTime, long endTime, int uid) ` Query network usage statistics details for a given uid. |
| ` https://developer.android.com/reference/android/app/usage/NetworkStats` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#queryDetailsForUidTag(int,%20java.lang.String,%20long,%20long,%20int,%20int)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long startTime, long endTime, int uid, int tag) ` Query network usage statistics details for a given uid and tag. |
| ` https://developer.android.com/reference/android/app/usage/NetworkStats` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#queryDetailsForUidTagState(int,%20java.lang.String,%20long,%20long,%20int,%20int,%20int)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long startTime, long endTime, int uid, int tag, int state) ` Query network usage statistics details for a given uid, tag, and state. |
| ` https://developer.android.com/reference/android/app/usage/NetworkStats` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#querySummary(int,%20java.lang.String,%20long,%20long)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long startTime, long endTime) ` Query network usage statistics summaries. |
| ` https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#querySummaryForDevice(int,%20java.lang.String,%20long,%20long)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long startTime, long endTime) ` Query network usage statistics summaries. |
| ` https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#querySummaryForUser(int,%20java.lang.String,%20long,%20long)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long startTime, long endTime) ` Query network usage statistics summaries. |
| ` void` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#registerUsageCallback(int,%20java.lang.String,%20long,%20android.app.usage.NetworkStatsManager.UsageCallback,%20android.os.Handler)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long thresholdBytes, https://developer.android.com/reference/android/app/usage/NetworkStatsManager.UsageCallback callback, https://developer.android.com/reference/android/os/Handler handler) ` Registers to receive notifications about data usage on specified networks. |
| ` void` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#registerUsageCallback(int,%20java.lang.String,%20long,%20android.app.usage.NetworkStatsManager.UsageCallback)(int networkType, https://developer.android.com/reference/java/lang/String subscriberId, long thresholdBytes, https://developer.android.com/reference/android/app/usage/NetworkStatsManager.UsageCallback callback) ` Registers to receive notifications about data usage on specified networks. |
| ` void` | ` https://developer.android.com/reference/android/app/usage/NetworkStatsManager#unregisterUsageCallback(android.app.usage.NetworkStatsManager.UsageCallback)(https://developer.android.com/reference/android/app/usage/NetworkStatsManager.UsageCallback callback) ` Unregisters callbacks on data usage. |

| ### 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*. | ||

## Public methods

### queryDetails

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

```
public NetworkStats queryDetails (int networkType, 
                String subscriberId, 
                long startTime, 
                long endTime)
```

Query network usage statistics details. Result filtered to include only uids belonging to
calling user. Result is aggregated over state but not aggregated over time, uid, tag,
metered, nor roaming. This means buckets' start and end timestamps are going to be between
'startTime' and 'endTime' parameters. State is going to be
`https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_ALL`, uid will vary,
tag `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#TAG_NONE`,
default network is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_ALL`,
metered is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL`,
and roaming is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL`.

Only includes buckets that atomically occur in the inclusive time range. Doesn't
interpolate across partial buckets. Since bucket length is in the order of hours, this
method cannot be used to measure data usage on a fine grained time scale.
This may take a long time, and apps should avoid calling this on their main thread.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: As defined in `https://developer.android.com/reference/android/net/ConnectivityManager`, e.g. `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE`, `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI` etc. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when querying for the mobile network type to receive usage for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `startTime` | `long`: Start of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: End of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/NetworkStats` | Statistics object or null if permissions are insufficient or error happened during statistics collection. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException` |   |
| `https://developer.android.com/reference/java/lang/SecurityException` |   |

### queryDetailsForUid

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

```
public NetworkStats queryDetailsForUid (int networkType, 
                String subscriberId, 
                long startTime, 
                long endTime, 
                int uid)
```

Query network usage statistics details for a given uid.
This may take a long time, and apps should avoid calling this on their main thread.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: As defined in `https://developer.android.com/reference/android/net/ConnectivityManager`, e.g. `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE`, `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI` etc. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when querying for the mobile network type to receive usage for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `startTime` | `long`: Start of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: End of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `uid` | `int`: UID of app <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/NetworkStats` | Statistics which is described above. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if permissions are insufficient to read network statistics. |

**See also:**

- `https://developer.android.com/reference/android/app/usage/NetworkStatsManager#queryDetailsForUidTagState(int,%20java.lang.String,%20long,%20long,%20int,%20int,%20int)`

### queryDetailsForUidTag

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

```
public NetworkStats queryDetailsForUidTag (int networkType, 
                String subscriberId, 
                long startTime, 
                long endTime, 
                int uid, 
                int tag)
```

Query network usage statistics details for a given uid and tag.

This may take a long time, and apps should avoid calling this on their main thread.
Only usable for uids belonging to calling user. Result is not aggregated over time.
This means buckets' start and end timestamps are going to be between 'startTime' and
'endTime' parameters. The uid is going to be the same as the 'uid' parameter, the tag
the same as the 'tag' parameter, and the state the same as the 'state' parameter.
defaultNetwork is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_ALL`,
metered is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL`, and
roaming is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL`.

Only includes buckets that atomically occur in the inclusive time range. Doesn't
interpolate across partial buckets. Since bucket length is in the order of hours, this
method cannot be used to measure data usage on a fine grained time scale.
This may take a long time, and apps should avoid calling this on their main thread.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: As defined in `https://developer.android.com/reference/android/net/ConnectivityManager`, e.g. `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE`, `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI` etc. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when querying for the mobile network type to receive usage for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `startTime` | `long`: Start of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: End of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `uid` | `int`: UID of app <br /> |
| `tag` | `int`: TAG of interest. Use `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#TAG_NONE` for aggregated data across all the tags. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/NetworkStats` | Statistics which is described above. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if permissions are insufficient to read network statistics. |

### queryDetailsForUidTagState

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

```
public NetworkStats queryDetailsForUidTagState (int networkType, 
                String subscriberId, 
                long startTime, 
                long endTime, 
                int uid, 
                int tag, 
                int state)
```

Query network usage statistics details for a given uid, tag, and state.

Only usable for uids belonging to calling user. Result is not aggregated over time.
This means buckets' start and end timestamps are going to be between 'startTime' and
'endTime' parameters. The uid is going to be the same as the 'uid' parameter, the tag
the same as the 'tag' parameter, and the state the same as the 'state' parameter.
defaultNetwork is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_ALL`,
metered is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL`, and
roaming is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL`.

Only includes buckets that atomically occur in the inclusive time range. Doesn't
interpolate across partial buckets. Since bucket length is in the order of hours, this
method cannot be used to measure data usage on a fine grained time scale.
This may take a long time, and apps should avoid calling this on their main thread.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: As defined in `https://developer.android.com/reference/android/net/ConnectivityManager`, e.g. `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE`, `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI` etc. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when querying for the mobile network type to receive usage for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `startTime` | `long`: Start of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: End of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `uid` | `int`: UID of app <br /> |
| `tag` | `int`: TAG of interest. Use `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#TAG_NONE` for aggregated data across all the tags. <br /> |
| `state` | `int`: state of interest. Use `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_ALL` to aggregate traffic from all states. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/NetworkStats` | Statistics which is described above. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if permissions are insufficient to read network statistics. |

### querySummary

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

```
public NetworkStats querySummary (int networkType, 
                String subscriberId, 
                long startTime, 
                long endTime)
```

Query network usage statistics summaries. Result filtered to include only uids belonging to
calling user. Result is aggregated over time, hence all buckets will have the same start and
end timestamps. Not aggregated over state, uid, default network, metered, or roaming. This
means buckets' start and end timestamps are going to be the same as the 'startTime' and
'endTime' parameters. State, uid, metered, and roaming are going to vary, and tag is going to
be the same.
This may take a long time, and apps should avoid calling this on their main thread.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: As defined in `https://developer.android.com/reference/android/net/ConnectivityManager`, e.g. `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE`, `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI` etc. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when querying for the mobile network type to receive usage for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `startTime` | `long`: Start of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: End of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/NetworkStats` | Statistics object or null if permissions are insufficient or error happened during statistics collection. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException` |   |
| `https://developer.android.com/reference/java/lang/SecurityException` |   |

### querySummaryForDevice

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

```
public NetworkStats.Bucket querySummaryForDevice (int networkType, 
                String subscriberId, 
                long startTime, 
                long endTime)
```

Query network usage statistics summaries. Result is summarised data usage for the whole
device. Result is a single Bucket aggregated over time, state, uid, tag, metered, and
roaming. This means the bucket's start and end timestamp are going to be the same as the
'startTime' and 'endTime' parameters. State is going to be
`https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_ALL`, uid `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#UID_ALL`,
tag `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#TAG_NONE`,
default network `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#DEFAULT_NETWORK_ALL`,
metered `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL`,
and roaming `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL`.
This may take a long time, and apps should avoid calling this on their main thread.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: As defined in `https://developer.android.com/reference/android/net/ConnectivityManager`, e.g. `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE`, `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI` etc. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when querying for the mobile network type to receive usage for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `startTime` | `long`: Start of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: End of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket` | Bucket object or null if permissions are insufficient or error happened during statistics collection. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException` |   |
| `https://developer.android.com/reference/java/lang/SecurityException` |   |

### querySummaryForUser

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

```
public NetworkStats.Bucket querySummaryForUser (int networkType, 
                String subscriberId, 
                long startTime, 
                long endTime)
```

Query network usage statistics summaries. Result is summarised data usage for all uids
belonging to calling user. Result is a single Bucket aggregated over time, state and uid.
This means the bucket's start and end timestamp are going to be the same as the 'startTime'
and 'endTime' parameters. State is going to be `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#STATE_ALL`,
uid `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#UID_ALL`, tag `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#TAG_NONE`,
metered `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#METERED_ALL`, and roaming
`https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket#ROAMING_ALL`.
This may take a long time, and apps should avoid calling this on their main thread.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: As defined in `https://developer.android.com/reference/android/net/ConnectivityManager`, e.g. `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE`, `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI` etc. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when querying for the mobile network type to receive usage for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `startTime` | `long`: Start of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |
| `endTime` | `long`: End of period. Defined in terms of "Unix time", see `https://developer.android.com/reference/java/lang/System#currentTimeMillis()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/usage/NetworkStats.Bucket` | Bucket object or null if permissions are insufficient or error happened during statistics collection. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException` |   |
| `https://developer.android.com/reference/java/lang/SecurityException` |   |

### registerUsageCallback

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

```
public void registerUsageCallback (int networkType, 
                String subscriberId, 
                long thresholdBytes, 
                NetworkStatsManager.UsageCallback callback, 
                Handler handler)
```

Registers to receive notifications about data usage on specified networks.

The callbacks will continue to be called as long as the process is live or
`https://developer.android.com/reference/android/app/usage/NetworkStatsManager#unregisterUsageCallback(android.app.usage.NetworkStatsManager.UsageCallback)` is called.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: Type of network to monitor. Either `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE` or `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI`. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when registering for the mobile network type to receive notifications for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `thresholdBytes` | `long`: Threshold in bytes to be notified on. <br /> |
| `callback` | `NetworkStatsManager.UsageCallback`: The `https://developer.android.com/reference/android/app/usage/NetworkStatsManager.UsageCallback` that the system will call when data usage has exceeded the specified threshold. This value cannot be `null`. <br /> |
| `handler` | `Handler`: to dispatch callback events through, otherwise if `null` it uses the calling thread. <br /> |

### registerUsageCallback

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

```
public void registerUsageCallback (int networkType, 
                String subscriberId, 
                long thresholdBytes, 
                NetworkStatsManager.UsageCallback callback)
```

Registers to receive notifications about data usage on specified networks.

The callbacks will continue to be called as long as the process is live or
`https://developer.android.com/reference/android/app/usage/NetworkStatsManager#unregisterUsageCallback(android.app.usage.NetworkStatsManager.UsageCallback)` is called.

<br />

| Parameters ||
|---|---|
| `networkType` | `int`: Type of network to monitor. Either `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_MOBILE` or `https://developer.android.com/reference/android/net/ConnectivityManager#TYPE_WIFI`. <br /> |
| `subscriberId` | `String`: If applicable, the subscriber id of the network interface. Starting with API level 29, the `subscriberId` is guarded by additional restrictions. Calling apps that do not meet the new requirements to access the `subscriberId` can provide a `null` value when registering for the mobile network type to receive notifications for all mobile networks. For additional details see `https://developer.android.com/reference/android/telephony/TelephonyManager#getSubscriberId()`. Starting with API level 31, calling apps can provide a `subscriberId` with wifi network type to receive usage for wifi networks which is under the given subscription if applicable. Otherwise, pass `null` when querying all wifi networks. |
| `thresholdBytes` | `long`: Threshold in bytes to be notified on. <br /> |
| `callback` | `NetworkStatsManager.UsageCallback`: The `https://developer.android.com/reference/android/app/usage/NetworkStatsManager.UsageCallback` that the system will call when data usage has exceeded the specified threshold. This value cannot be `null`. <br /> |

### unregisterUsageCallback

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

```
public void unregisterUsageCallback (NetworkStatsManager.UsageCallback callback)
```

Unregisters callbacks on data usage.

<br />

| Parameters ||
|---|---|
| `callback` | `NetworkStatsManager.UsageCallback`: The `https://developer.android.com/reference/android/app/usage/NetworkStatsManager.UsageCallback` used when registering. This value cannot be `null`. <br /> |