# ConnectivityManagerCompat

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:[Constants](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#constants)\|[Methods](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#)  

# ConnectivityManagerCompat

| 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
ConnectivityManagerCompat
`  
`

extends Object


``


`

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

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                                                    ### Constants                                                                                                                                                     ||
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [RESTRICT_BACKGROUND_STATUS_DISABLED](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#RESTRICT_BACKGROUND_STATUS_DISABLED) Device is not restricting metered network activity while application is running on background.                                            |
| `int` | [RESTRICT_BACKGROUND_STATUS_ENABLED](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#RESTRICT_BACKGROUND_STATUS_ENABLED) Device is restricting metered network activity while application is running on background.                                                  |
| `int` | [RESTRICT_BACKGROUND_STATUS_WHITELISTED](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#RESTRICT_BACKGROUND_STATUS_WHITELISTED) Device is restricting metered network activity while application is running on background, but application is allowed to bypass it. |

|                                                                                                                                                                                                                                                                                                                                                                           ### Public methods                                                                                                                                                                                                                                                                                                                                                                            ||
|-----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[NetworkInfo](https://developer.android.com/reference/android/net/NetworkInfo.html) | ` `[getNetworkInfoFromBroadcast](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#getNetworkInfoFromBroadcast(android.net.ConnectivityManager, android.content.Intent))`(`[ConnectivityManager](https://developer.android.com/reference/android/net/ConnectivityManager.html)` cm, `[Intent](https://developer.android.com/reference/android/content/Intent.html)` intent) ` Return the[NetworkInfo](https://developer.android.com/reference/android/net/NetworkInfo.html)that caused the given[CONNECTIVITY_ACTION](https://developer.android.com/reference/android/net/ConnectivityManager.html#CONNECTIVITY_ACTION)broadcast. |
| ` static int`                                                                                 | ` `[getRestrictBackgroundStatus](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#getRestrictBackgroundStatus(android.net.ConnectivityManager))`(`[ConnectivityManager](https://developer.android.com/reference/android/net/ConnectivityManager.html)` cm) ` Determines if the calling application is subject to metered network restrictions while running on background.                                                                                                                                                                                                                                                       |
| ` static boolean`                                                                             | ` `[isActiveNetworkMetered](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#isActiveNetworkMetered(android.net.ConnectivityManager))`(`[ConnectivityManager](https://developer.android.com/reference/android/net/ConnectivityManager.html)` cm) ` Returns if the currently active data network is metered.                                                                                                                                                                                                                                                                                                                      |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#)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() `                    | ||

## Constants

### RESTRICT_BACKGROUND_STATUS_DISABLED

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

```
int RESTRICT_BACKGROUND_STATUS_DISABLED
```

Device is not restricting metered network activity while application is running on background.

<br />

Constant Value: 1 (0x00000001)  

### RESTRICT_BACKGROUND_STATUS_ENABLED

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

```
int RESTRICT_BACKGROUND_STATUS_ENABLED
```

Device is restricting metered network activity while application is running on background.

In this state, application should not try to use the network while running on background, because it would be denied.

<br />

Constant Value: 3 (0x00000003)  

### RESTRICT_BACKGROUND_STATUS_WHITELISTED

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

```
int RESTRICT_BACKGROUND_STATUS_WHITELISTED
```

Device is restricting metered network activity while application is running on background, but application is allowed to bypass it.

In this state, application should take action to mitigate metered network access. For example, a music streaming application should switch to a low-bandwidth bitrate.

<br />

Constant Value: 2 (0x00000002)

## Public methods

### getNetworkInfoFromBroadcast

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

```
NetworkInfo getNetworkInfoFromBroadcast (ConnectivityManager cm, 
                Intent intent)
```

Return the[NetworkInfo](https://developer.android.com/reference/android/net/NetworkInfo.html)that caused the given[CONNECTIVITY_ACTION](https://developer.android.com/reference/android/net/ConnectivityManager.html#CONNECTIVITY_ACTION)broadcast. This obtains the current state from[ConnectivityManager](https://developer.android.com/reference/android/net/ConnectivityManager.html)instead of using the potentially-stale value from[EXTRA_NETWORK_INFO](https://developer.android.com/reference/android/net/ConnectivityManager.html#EXTRA_NETWORK_INFO). May be`null`.

Requires the[ACCESS_NETWORK_STATE](https://developer.android.com/reference/android/Manifest.permission#ACCESS_NETWORK_STATE)permission.

|               Parameters               ||
|----------|------------------------------|
| `cm`     | `ConnectivityManager` <br /> |
| `intent` | `Intent` <br />              |

|                                           Returns                                           ||
|-------------------------------------------------------------------------------------|--------|
| [NetworkInfo](https://developer.android.com/reference/android/net/NetworkInfo.html) | <br /> |

### getRestrictBackgroundStatus

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

```
int getRestrictBackgroundStatus (ConnectivityManager cm)
```

Determines if the calling application is subject to metered network restrictions while running on background.

<br />

|             Parameters             ||
|------|------------------------------|
| `cm` | `ConnectivityManager` <br /> |

|                                                                                                                                                                                                                                                             Returns                                                                                                                                                                                                                                                              ||
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [RESTRICT_BACKGROUND_STATUS_DISABLED](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#RESTRICT_BACKGROUND_STATUS_DISABLED),[RESTRICT_BACKGROUND_STATUS_ENABLED](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#RESTRICT_BACKGROUND_STATUS_ENABLED), or[RESTRICT_BACKGROUND_STATUS_WHITELISTED](https://developer.android.com/reference/android/support/v4/net/ConnectivityManagerCompat#RESTRICT_BACKGROUND_STATUS_WHITELISTED) <br /> |

### isActiveNetworkMetered

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

```
boolean isActiveNetworkMetered (ConnectivityManager cm)
```

Returns if the currently active data network is metered. A network is classified as metered when the user is sensitive to heavy data usage on that connection due to monetary costs, data limitations or battery/performance issues. You should check this before doing large data transfers, and warn the user or delay the operation until another network is available.

This method requires the caller to hold the permission[ACCESS_NETWORK_STATE](https://developer.android.com/reference/android/Manifest.permission#ACCESS_NETWORK_STATE).

Requires the[ACCESS_NETWORK_STATE](https://developer.android.com/reference/android/Manifest.permission#ACCESS_NETWORK_STATE)permission.

|             Parameters             ||
|------|------------------------------|
| `cm` | `ConnectivityManager` <br /> |

|                                     Returns                                     ||
|-----------|----------------------------------------------------------------------|
| `boolean` | `true`if large transfers should be avoided, otherwise`false`. <br /> |

-

  ## Classes

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