public final class ConnectivityManagerCompat extends Object
ConnectivityManager
introduced after
API level 16 in a backwards compatible fashion.Modifier and Type | Class and Description |
---|---|
static interface |
ConnectivityManagerCompat.RestrictBackgroundStatus |
Modifier and Type | Field and Description |
---|---|
static int |
RESTRICT_BACKGROUND_STATUS_DISABLED
Device is not restricting metered network activity while application is running on
background.
|
static int |
RESTRICT_BACKGROUND_STATUS_ENABLED
Device is restricting metered network activity while application is running on background.
|
static int |
RESTRICT_BACKGROUND_STATUS_WHITELISTED
Device is restricting metered network activity while application is running on background,
but application is allowed to bypass it.
|
Modifier and Type | Method and Description |
---|---|
static NetworkInfo |
getNetworkInfoFromBroadcast(ConnectivityManager cm,
Intent intent)
Return the
NetworkInfo that caused the given
ConnectivityManager.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.
|
public static final int RESTRICT_BACKGROUND_STATUS_DISABLED
public static final int RESTRICT_BACKGROUND_STATUS_WHITELISTED
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.
public static final int RESTRICT_BACKGROUND_STATUS_ENABLED
In this state, application should not try to use the network while running on background, because it would be denied.
public static boolean isActiveNetworkMetered(ConnectivityManager cm)
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
true
if large transfers should be avoided, otherwise
false
.public static NetworkInfo getNetworkInfoFromBroadcast(ConnectivityManager cm, Intent intent)
NetworkInfo
that caused the given
ConnectivityManager.CONNECTIVITY_ACTION
broadcast. This obtains
the current state from ConnectivityManager
instead of using the
potentially-stale value from
ConnectivityManager.EXTRA_NETWORK_INFO
. May be null
.public static int getRestrictBackgroundStatus(ConnectivityManager cm)