NetworkCapabilities
class NetworkCapabilities : Parcelable
| kotlin.Any | |
| ↳ | android.net.NetworkCapabilities |
Representation of the capabilities of an active network. Instances are typically obtained through NetworkCallback#onCapabilitiesChanged(Network, NetworkCapabilities) or ConnectivityManager#getNetworkCapabilities(Network).
This replaces the old ConnectivityManager#TYPE_MOBILE method of network selection. Rather than indicate a need for Wi-Fi because an application needs high bandwidth and risk obsolescence when a new, fast network appears (like LTE), the application should specify it needs high bandwidth. Similarly if an application needs an unmetered network for a bulk transfer it can specify that rather than assuming all cellular based connections are metered and all Wi-Fi based connections are not.
Summary
| Constants | |
|---|---|
| static Int |
Indicates that this network was found to have a captive portal in place last time it was probed. |
| static Int |
Indicates this is a network that has the ability to reach the carrier's CBS servers, used for carrier specific services. |
| static Int |
Indicates this is a network that has the ability to reach the carrier's DUN or tethering gateway. |
| static Int |
Indicates this is a network that has the ability to reach a carrier's Emergency IMS servers or other services, used for network signaling during emergency calls. |
| static Int |
Indicates that this network is available for use by apps, and not a network that is being kept up in the background to facilitate fast network switching. |
| static Int |
Indicates this is a network that has the ability to reach the carrier's FOTA portal, used for over the air updates. |
| static Int |
Indicates this is a network that has the ability to reach a carrier's Initial Attach servers. |
| static Int |
Indicates this is a network that has the ability to reach the carrier's IMS servers, used for network registration and signaling. |
| static Int |
Indicates that this network should be able to reach the internet. |
| static Int |
Indicates this is a network that has the ability to reach a carrier's Mission Critical servers. |
| static Int |
Indicates this is a network that has the ability to reach the carrier's MMSC for sending and receiving MMS messages. |
| static Int |
Indicates that this network is not congested. |
| static Int |
Indicates that this network is unmetered. |
| static Int |
Indicates that this network is available for general use. |
| static Int |
Indicates that this network is not roaming. |
| static Int |
Indicates that this network is not currently suspended. |
| static Int |
Indicates that this network is not a VPN. |
| static Int |
Indicates this is a network that has the ability to reach a carrier's RCS servers, used for Rich Communication Services. |
| static Int |
Indicates this is a network that has the ability to reach the carrier's SUPL server, used to retrieve GPS information. |
| static Int |
This capability will be set for networks that are generally metered, but are currently unmetered, e. |
| static Int |
Indicates that the user has indicated implicit trust of this network. |
| static Int |
Indicates that connectivity on this network was successfully validated. |
| static Int |
Indicates this is a network that has the ability to reach a Wi-Fi direct peer. |
| static Int |
Indicates this is a network that has the ability to reach a carrier's XCAP servers, used for configuration and control. |
| static Int |
Magic value that indicates no signal strength provided. |
| static Int |
Indicates this network uses a Bluetooth transport. |
| static Int |
Indicates this network uses a Cellular transport. |
| static Int |
Indicates this network uses an Ethernet transport. |
| static Int |
Indicates this network uses a LoWPAN transport. |
| static Int |
Indicates this network uses a VPN transport. |
| static Int |
Indicates this network uses a Wi-Fi transport. |
| static Int |
Indicates this network uses a Wi-Fi Aware transport. |
| Inherited constants | |
|---|---|
| Public constructors | |
|---|---|
<init>() |
|
<init>(nc: NetworkCapabilities!) |
|
| Public methods | |
|---|---|
| Int | |
| Boolean |
Indicates whether some other object is "equal to" this one. |
| Int |
Retrieves the downstream bandwidth for this network in Kbps. |
| Int |
Retrieves the upstream bandwidth for this network in Kbps. |
| NetworkSpecifier? |
Gets the optional bearer specific network specifier. |
| Int |
Retrieves the UID of the app that owns this network. |
| Int |
Retrieves the signal strength. |
| TransportInfo? |
Returns a transport-specific information container. |
| Boolean |
hasCapability(capability: Int)Tests for the presence of a capability on this instance. |
| Boolean |
hasTransport(transportType: Int)Tests for the presence of a transport on this instance. |
| Int |
hashCode() |
| String |
toString()Returns a string representation of the object. |
| Unit |
writeToParcel(dest: Parcel!, flags: Int) |
| Properties | |
|---|---|
| static Parcelable.Creator<NetworkCapabilities!> | |
Constants
NET_CAPABILITY_CAPTIVE_PORTAL
static val NET_CAPABILITY_CAPTIVE_PORTAL: Int
Indicates that this network was found to have a captive portal in place last time it was probed.
Value: 17
NET_CAPABILITY_CBS
static val NET_CAPABILITY_CBS: Int
Indicates this is a network that has the ability to reach the carrier's CBS servers, used for carrier specific services.
Value: 5
NET_CAPABILITY_DUN
static val NET_CAPABILITY_DUN: Int
Indicates this is a network that has the ability to reach the carrier's DUN or tethering gateway.
Value: 2
NET_CAPABILITY_EIMS
static val NET_CAPABILITY_EIMS: Int
Indicates this is a network that has the ability to reach a carrier's Emergency IMS servers or other services, used for network signaling during emergency calls.
Value: 10
NET_CAPABILITY_FOREGROUND
static val NET_CAPABILITY_FOREGROUND: Int
Indicates that this network is available for use by apps, and not a network that is being kept up in the background to facilitate fast network switching.
Value: 19
NET_CAPABILITY_FOTA
static val NET_CAPABILITY_FOTA: Int
Indicates this is a network that has the ability to reach the carrier's FOTA portal, used for over the air updates.
Value: 3
NET_CAPABILITY_IA
static val NET_CAPABILITY_IA: Int
Indicates this is a network that has the ability to reach a carrier's Initial Attach servers.
Value: 7
NET_CAPABILITY_IMS
static val NET_CAPABILITY_IMS: Int
Indicates this is a network that has the ability to reach the carrier's IMS servers, used for network registration and signaling.
Value: 4
NET_CAPABILITY_INTERNET
static val NET_CAPABILITY_INTERNET: Int
Indicates that this network should be able to reach the internet.
Value: 12
NET_CAPABILITY_MCX
static val NET_CAPABILITY_MCX: Int
Indicates this is a network that has the ability to reach a carrier's Mission Critical servers.
Value: 23
NET_CAPABILITY_MMS
static val NET_CAPABILITY_MMS: Int
Indicates this is a network that has the ability to reach the carrier's MMSC for sending and receiving MMS messages.
Value: 0
NET_CAPABILITY_NOT_CONGESTED
static val NET_CAPABILITY_NOT_CONGESTED: Int
Indicates that this network is not congested.
When a network is congested, applications should defer network traffic that can be done at a later time, such as uploading analytics.
Value: 20
NET_CAPABILITY_NOT_METERED
static val NET_CAPABILITY_NOT_METERED: Int
Indicates that this network is unmetered.
Value: 11
NET_CAPABILITY_NOT_RESTRICTED
static val NET_CAPABILITY_NOT_RESTRICTED: Int
Indicates that this network is available for general use. If this is not set applications should not attempt to communicate on this network. Note that this is simply informative and not enforcement - enforcement is handled via other means. Set by default.
Value: 13
NET_CAPABILITY_NOT_ROAMING
static val NET_CAPABILITY_NOT_ROAMING: Int
Indicates that this network is not roaming.
Value: 18
NET_CAPABILITY_NOT_SUSPENDED
static val NET_CAPABILITY_NOT_SUSPENDED: Int
Indicates that this network is not currently suspended.
When a network is suspended, the network's IP addresses and any connections established on the network remain valid, but the network is temporarily unable to transfer data. This can happen, for example, if a cellular network experiences a temporary loss of signal, such as when driving through a tunnel, etc. A network with this capability is not suspended, so is expected to be able to transfer data.
Value: 21
NET_CAPABILITY_NOT_VPN
static val NET_CAPABILITY_NOT_VPN: Int
Indicates that this network is not a VPN. This capability is set by default and should be explicitly cleared for VPN networks.
Value: 15
NET_CAPABILITY_RCS
static val NET_CAPABILITY_RCS: Int
Indicates this is a network that has the ability to reach a carrier's RCS servers, used for Rich Communication Services.
Value: 8
NET_CAPABILITY_SUPL
static val NET_CAPABILITY_SUPL: Int
Indicates this is a network that has the ability to reach the carrier's SUPL server, used to retrieve GPS information.
Value: 1
NET_CAPABILITY_TEMPORARILY_NOT_METERED
static val NET_CAPABILITY_TEMPORARILY_NOT_METERED: Int
This capability will be set for networks that are generally metered, but are currently unmetered, e.g., because the user is in a particular area. This capability can be changed at any time. When it is removed, applications are responsible for stopping any data transfer that should not occur on a metered network.
Value: 25
NET_CAPABILITY_TRUSTED
static val NET_CAPABILITY_TRUSTED: Int
Indicates that the user has indicated implicit trust of this network. This generally means it's a sim-selected carrier, a plugged in ethernet, a paired BT device or a wifi the user asked to connect to. Untrusted networks are probably limited to unknown wifi AP. Set by default.
Value: 14
NET_CAPABILITY_VALIDATED
static val NET_CAPABILITY_VALIDATED: Int
Indicates that connectivity on this network was successfully validated. For example, for a network with NET_CAPABILITY_INTERNET, it means that Internet connectivity was successfully detected.
Value: 16
NET_CAPABILITY_WIFI_P2P
static val NET_CAPABILITY_WIFI_P2P: Int
Indicates this is a network that has the ability to reach a Wi-Fi direct peer.
Value: 6
NET_CAPABILITY_XCAP
static val NET_CAPABILITY_XCAP: Int
Indicates this is a network that has the ability to reach a carrier's XCAP servers, used for configuration and control.
Value: 9
SIGNAL_STRENGTH_UNSPECIFIED
static val SIGNAL_STRENGTH_UNSPECIFIED: Int
Magic value that indicates no signal strength provided. A request specifying this value is always satisfied.
Value: -2147483648
TRANSPORT_BLUETOOTH
static val TRANSPORT_BLUETOOTH: Int
Indicates this network uses a Bluetooth transport.
Value: 2
TRANSPORT_CELLULAR
static val TRANSPORT_CELLULAR: Int
Indicates this network uses a Cellular transport.
Value: 0
TRANSPORT_ETHERNET
static val TRANSPORT_ETHERNET: Int
Indicates this network uses an Ethernet transport.
Value: 3
TRANSPORT_LOWPAN
static val TRANSPORT_LOWPAN: Int
Indicates this network uses a LoWPAN transport.
Value: 6
TRANSPORT_VPN
static val TRANSPORT_VPN: Int
Indicates this network uses a VPN transport.
Value: 4
TRANSPORT_WIFI
static val TRANSPORT_WIFI: Int
Indicates this network uses a Wi-Fi transport.
Value: 1
TRANSPORT_WIFI_AWARE
static val TRANSPORT_WIFI_AWARE: Int
Indicates this network uses a Wi-Fi Aware transport.
Value: 5
Public constructors
Public methods
describeContents
fun describeContents(): Int
| Return | |
|---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR |
equals
fun equals(other: Any?): Boolean
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation on non-null object references:
- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
| Parameters | |
|---|---|
obj |
This value may be null. |
| Return | |
|---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
getLinkDownstreamBandwidthKbps
fun getLinkDownstreamBandwidthKbps(): Int
Retrieves the downstream bandwidth for this network in Kbps. This always only refers to the estimated first hop transport bandwidth.
| Return | |
|---|---|
Int |
The estimated first hop downstream (network to device) bandwidth. |
getLinkUpstreamBandwidthKbps
fun getLinkUpstreamBandwidthKbps(): Int
Retrieves the upstream bandwidth for this network in Kbps. This always only refers to the estimated first hop transport bandwidth.
| Return | |
|---|---|
Int |
The estimated first hop upstream (device to network) bandwidth. |
getNetworkSpecifier
fun getNetworkSpecifier(): NetworkSpecifier?
Gets the optional bearer specific network specifier. May be null if not set.
| Return | |
|---|---|
NetworkSpecifier? |
The optional NetworkSpecifier specifying the bearer specific network specifier or null. |
getOwnerUid
fun getOwnerUid(): Int
Retrieves the UID of the app that owns this network.
For user privacy reasons, this field will only be populated if the following conditions are met:
The caller is the network owner, AND one of the following sets of requirements is met:
- The described Network is a VPN
OR:
- The calling app is the network owner
- The calling app has the ACCESS_FINE_LOCATION permission granted
- The user's location toggle is on
getSignalStrength
fun getSignalStrength(): Int
Retrieves the signal strength.
| Return | |
|---|---|
Int |
The bearer-specific signal strength. |
getTransportInfo
fun getTransportInfo(): TransportInfo?
Returns a transport-specific information container. The application may cast this container to a concrete sub-class based on its knowledge of the network request. The application should be able to deal with a null return value or an invalid case, e.g. use instanceof operator to verify expected type.
| Return | |
|---|---|
TransportInfo? |
A concrete implementation of the TransportInfo class or null if not available for the network. |
hasCapability
fun hasCapability(capability: Int): Boolean
Tests for the presence of a capability on this instance.
| Return | |
|---|---|
Boolean |
true if set on this instance. |
hasTransport
fun hasTransport(transportType: Int): Boolean
Tests for the presence of a transport on this instance.
| Parameters | |
|---|---|
transportType |
Int: the transport type to be tested for. Value is android.net.NetworkCapabilities#TRANSPORT_CELLULAR, android.net.NetworkCapabilities#TRANSPORT_WIFI, android.net.NetworkCapabilities#TRANSPORT_BLUETOOTH, android.net.NetworkCapabilities#TRANSPORT_ETHERNET, android.net.NetworkCapabilities#TRANSPORT_VPN, android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE, android.net.NetworkCapabilities#TRANSPORT_LOWPAN, or android.net.NetworkCapabilities.TRANSPORT_TEST |
| Return | |
|---|---|
Boolean |
true if set on this instance. |
toString
fun toString(): String
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
| Return | |
|---|---|
String |
This value cannot be null. |
writeToParcel
fun writeToParcel(
dest: Parcel!,
flags: Int
): Unit
| Parameters | |
|---|---|
dest |
Parcel!: The Parcel in which the object should be written. |
flags |
Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |