Android APIs
public final class

NetworkCapabilities

extends Object
implements Parcelable
java.lang.Object
   ↳ android.net.NetworkCapabilities

Class Overview

This class represents the capabilities of a network. This is used both to specify needs to ConnectivityManager and when inspecting a network. Note that this replaces the old TYPE_MOBILE method of network selection. Rather than indicate a need for Wi-Fi because an application needs high bandwidth and risk obselence 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
int NET_CAPABILITY_CBS Indicates this is a network that has the ability to reach the carrier's CBS servers, used for carrier specific services.
int NET_CAPABILITY_DUN Indicates this is a network that has the ability to reach the carrier's DUN or tethering gateway.
int NET_CAPABILITY_EIMS Indicates this is a network that has the ability to reach a carrier's Emergency IMS servers, used for network signaling during emergency calls.
int NET_CAPABILITY_FOTA Indicates this is a network that has the ability to reach the carrier's FOTA portal, used for over the air updates.
int NET_CAPABILITY_IA Indicates this is a network that has the ability to reach a carrier's Initial Attach servers.
int NET_CAPABILITY_IMS Indicates this is a network that has the ability to reach the carrier's IMS servers, used for network registration and signaling.
int NET_CAPABILITY_INTERNET Indicates that this network should be able to reach the internet.
int NET_CAPABILITY_MMS Indicates this is a network that has the ability to reach the carrier's MMSC for sending and receiving MMS messages.
int NET_CAPABILITY_NOT_METERED Indicates that this network is unmetered.
int NET_CAPABILITY_NOT_RESTRICTED Indicates that this network is available for general use.
int NET_CAPABILITY_RCS Indicates this is a network that has the ability to reach a carrier's RCS servers, used for Rich Communication Services.
int NET_CAPABILITY_SUPL Indicates this is a network that has the ability to reach the carrier's SUPL server, used to retrieve GPS information.
int NET_CAPABILITY_WIFI_P2P Indicates this is a network that has the ability to reach a Wi-Fi direct peer.
int NET_CAPABILITY_XCAP Indicates this is a network that has the ability to reach a carrier's XCAP servers, used for configuration and control.
int TRANSPORT_BLUETOOTH Indicates this network uses a Bluetooth transport.
int TRANSPORT_CELLULAR Indicates this network uses a Cellular transport.
int TRANSPORT_ETHERNET Indicates this network uses an Ethernet transport.
int TRANSPORT_WIFI Indicates this network uses a Wi-Fi transport.
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<NetworkCapabilities> CREATOR
Public Constructors
NetworkCapabilities(NetworkCapabilities nc)
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
boolean equals(Object obj)
Compares this instance with the specified object and indicates if they are equal.
int getLinkDownstreamBandwidthKbps()
Retrieves the downstream bandwidth for this network in Kbps.
int getLinkUpstreamBandwidthKbps()
Retrieves the upstream bandwidth for this network in Kbps.
boolean hasCapability(int capability)
Tests for the presence of a capabilitity on this instance.
boolean hasTransport(int transportType)
Tests for the presence of a transport on this instance.
int hashCode()
Returns an integer hash code for this object.
String toString()
Returns a string containing a concise, human-readable description of this object.
void writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final int NET_CAPABILITY_CBS

Indicates this is a network that has the ability to reach the carrier's CBS servers, used for carrier specific services.

Constant Value: 5 (0x00000005)

public static final int NET_CAPABILITY_DUN

Indicates this is a network that has the ability to reach the carrier's DUN or tethering gateway.

Constant Value: 2 (0x00000002)

public static final int NET_CAPABILITY_EIMS

Indicates this is a network that has the ability to reach a carrier's Emergency IMS servers, used for network signaling during emergency calls.

Constant Value: 10 (0x0000000a)

public static final int NET_CAPABILITY_FOTA

Indicates this is a network that has the ability to reach the carrier's FOTA portal, used for over the air updates.

Constant Value: 3 (0x00000003)

public static final int NET_CAPABILITY_IA

Indicates this is a network that has the ability to reach a carrier's Initial Attach servers.

Constant Value: 7 (0x00000007)

public static final int NET_CAPABILITY_IMS

Indicates this is a network that has the ability to reach the carrier's IMS servers, used for network registration and signaling.

Constant Value: 4 (0x00000004)

public static final int NET_CAPABILITY_INTERNET

Indicates that this network should be able to reach the internet.

Constant Value: 12 (0x0000000c)

public static final int NET_CAPABILITY_MMS

Indicates this is a network that has the ability to reach the carrier's MMSC for sending and receiving MMS messages.

Constant Value: 0 (0x00000000)

public static final int NET_CAPABILITY_NOT_METERED

Indicates that this network is unmetered.

Constant Value: 11 (0x0000000b)

public static final int NET_CAPABILITY_NOT_RESTRICTED

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.

Constant Value: 13 (0x0000000d)

public static final int NET_CAPABILITY_RCS

Indicates this is a network that has the ability to reach a carrier's RCS servers, used for Rich Communication Services.

Constant Value: 8 (0x00000008)

public static final int NET_CAPABILITY_SUPL

Indicates this is a network that has the ability to reach the carrier's SUPL server, used to retrieve GPS information.

Constant Value: 1 (0x00000001)

public static final int NET_CAPABILITY_WIFI_P2P

Indicates this is a network that has the ability to reach a Wi-Fi direct peer.

Constant Value: 6 (0x00000006)

public static final int NET_CAPABILITY_XCAP

Indicates this is a network that has the ability to reach a carrier's XCAP servers, used for configuration and control.

Constant Value: 9 (0x00000009)

public static final int TRANSPORT_BLUETOOTH

Indicates this network uses a Bluetooth transport.

Constant Value: 2 (0x00000002)

public static final int TRANSPORT_CELLULAR

Indicates this network uses a Cellular transport.

Constant Value: 0 (0x00000000)

public static final int TRANSPORT_ETHERNET

Indicates this network uses an Ethernet transport.

Constant Value: 3 (0x00000003)

public static final int TRANSPORT_WIFI

Indicates this network uses a Wi-Fi transport.

Constant Value: 1 (0x00000001)

Fields

public static final Creator<NetworkCapabilities> CREATOR

Public Constructors

public NetworkCapabilities (NetworkCapabilities nc)

Public Methods

public int describeContents ()

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public boolean equals (Object obj)

Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method.

The general contract for the equals and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.

Parameters
obj the object to compare this instance with.
Returns
  • true if the specified object is equal to this Object; false otherwise.

public int getLinkDownstreamBandwidthKbps ()

Retrieves the downstream bandwidth for this network in Kbps. This always only refers to the estimated first hop transport bandwidth.

Returns
  • The estimated first hop downstream (network to device) bandwidth.

public int getLinkUpstreamBandwidthKbps ()

Retrieves the upstream bandwidth for this network in Kbps. This always only refers to the estimated first hop transport bandwidth.

Returns
  • The estimated first hop upstream (device to network) bandwidth.

public boolean hasCapability (int capability)

Tests for the presence of a capabilitity on this instance.

Parameters
capability the NetworkCapabilities.NET_CAPABILITY_* to be tested for.
Returns
  • true if set on this instance.

public boolean hasTransport (int transportType)

Tests for the presence of a transport on this instance.

Parameters
transportType the NetworkCapabilities.TRANSPORT_* to be tested for.
Returns
  • true if set on this instance.

public int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
  • this object's hash code.

public String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public void writeToParcel (Parcel dest, int flags)

Flatten this object in to a Parcel.

Parameters
dest The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.