Skip to content

Most visited

Recently visited

navigation

ConnectivityManagerCompat

public final class ConnectivityManagerCompat
extends Object

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


Helper for accessing features in ConnectivityManager introduced after API level 16 in a backwards compatible fashion.

Summary

Constants

int RESTRICT_BACKGROUND_STATUS_DISABLED

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

int RESTRICT_BACKGROUND_STATUS_ENABLED

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

int 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 getNetworkInfoFromBroadcast(ConnectivityManager cm, Intent intent)

Return the NetworkInfo that caused the given CONNECTIVITY_ACTION broadcast.

static int getRestrictBackgroundStatus(ConnectivityManager cm)

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

static boolean isActiveNetworkMetered(ConnectivityManager cm)

Returns if the currently active data network is metered.

Inherited methods

From class java.lang.Object

Constants

RESTRICT_BACKGROUND_STATUS_DISABLED

int RESTRICT_BACKGROUND_STATUS_DISABLED

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

Constant Value: 1 (0x00000001)

RESTRICT_BACKGROUND_STATUS_ENABLED

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.

Constant Value: 3 (0x00000003)

RESTRICT_BACKGROUND_STATUS_WHITELISTED

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.

Constant Value: 2 (0x00000002)

Public methods

getNetworkInfoFromBroadcast

NetworkInfo getNetworkInfoFromBroadcast (ConnectivityManager cm, 
                Intent intent)

Return the NetworkInfo that caused the given CONNECTIVITY_ACTION broadcast. This obtains the current state from ConnectivityManager instead of using the potentially-stale value from EXTRA_NETWORK_INFO. May be null.

Parameters
cm ConnectivityManager
intent Intent
Returns
NetworkInfo

getRestrictBackgroundStatus

int getRestrictBackgroundStatus (ConnectivityManager cm)

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

Parameters
cm ConnectivityManager
Returns
int RESTRICT_BACKGROUND_STATUS_DISABLED, RESTRICT_BACKGROUND_STATUS_ENABLED, or RESTRICT_BACKGROUND_STATUS_WHITELISTED

isActiveNetworkMetered

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.

Parameters
cm ConnectivityManager
Returns
boolean true if large transfers should be avoided, otherwise false.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.