ConnectivityManagerCompat
class ConnectivityManagerCompat
Helper for accessing features in ConnectivityManager.
Summary
Constants |
|
|---|---|
const Int |
Device is not restricting metered network activity while application is running on background. |
const Int |
Device is restricting metered network activity while application is running on background. |
const Int |
Device is restricting metered network activity while application is running on background, but application is allowed to bypass it. |
Public functions |
|
|---|---|
java-static NetworkInfo? |
@RequiresPermission(value = Manifest.permission.ACCESS_NETWORK_STATE)Return the |
java-static Int |
Determines if the calling application is subject to metered network restrictions while running on background. |
java-static Boolean |
@ReplaceWith(expression = "cm.isActiveNetworkMetered()")This function is deprecated. Call |
Constants
RESTRICT_BACKGROUND_STATUS_DISABLED
const val RESTRICT_BACKGROUND_STATUS_DISABLED = 1: Int
Device is not restricting metered network activity while application is running on background.
RESTRICT_BACKGROUND_STATUS_ENABLED
const val RESTRICT_BACKGROUND_STATUS_ENABLED = 3: Int
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.
RESTRICT_BACKGROUND_STATUS_WHITELISTED
const val RESTRICT_BACKGROUND_STATUS_WHITELISTED = 2: Int
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.
Public functions
getNetworkInfoFromBroadcast
@RequiresPermission(value = Manifest.permission.ACCESS_NETWORK_STATE)
java-static fun getNetworkInfoFromBroadcast(cm: ConnectivityManager, intent: Intent): NetworkInfo?
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.
getRestrictBackgroundStatus
java-static fun getRestrictBackgroundStatus(cm: ConnectivityManager): Int
Determines if the calling application is subject to metered network restrictions while running on background.
@ReplaceWith(expression = "cm.isActiveNetworkMetered()")
@RequiresPermission(value = Manifest.permission.ACCESS_NETWORK_STATE)
java-static funisActiveNetworkMetered(cm: ConnectivityManager): Boolean
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.
| Returns | |
|---|---|
Boolean |
|