Google is committed to advancing racial equity for Black communities. See how.
Added in API level 21

Network

open class Network : Parcelable
kotlin.Any
   ↳ android.net.Network

Identifies a Network. This is supplied to applications via ConnectivityManager.NetworkCallback in response to the active ConnectivityManager#requestNetwork or passive ConnectivityManager#registerNetworkCallback calls. It is used to direct traffic to the given Network, either on a Socket basis through a targeted SocketFactory or process-wide via ConnectivityManager#bindProcessToNetwork.

Summary

Inherited constants
Public methods
open Unit

Binds the specified DatagramSocket to this Network.

open Unit
bindSocket(socket: Socket!)

Binds the specified Socket to this Network.

open Unit

Binds the specified FileDescriptor to this Network.

open Int

open Boolean
equals(other: Any?)

open static Network!
fromNetworkHandle(networkHandle: Long)

Returns a Network object given a handle returned from getNetworkHandle.

open Array<InetAddress!>!

Operates the same as InetAddress.getAllByName except that host resolution is done on this network.

open InetAddress!
getByName(host: String!)

Operates the same as InetAddress.getByName except that host resolution is done on this network.

open Long

Returns a handle representing this Network, for use with the NDK API.

open SocketFactory!

Returns a SocketFactory bound to this network.

open Int

open URLConnection!

Opens the specified URL on this Network, such that all traffic will be sent on this Network.

open URLConnection!
openConnection(url: URL!, proxy: Proxy!)

Opens the specified URL on this Network, such that all traffic will be sent on this Network.

open String

open Unit
writeToParcel(dest: Parcel!, flags: Int)

Properties
static Parcelable.Creator<Network!>

Public methods

bindSocket

Added in API level 22
open fun bindSocket(socket: DatagramSocket!): Unit

Binds the specified DatagramSocket to this Network. All data traffic on the socket will be sent on this Network, irrespective of any process-wide network binding set by ConnectivityManager#bindProcessToNetwork. The socket must not be connected.

bindSocket

Added in API level 21
open fun bindSocket(socket: Socket!): Unit

Binds the specified Socket to this Network. All data traffic on the socket will be sent on this Network, irrespective of any process-wide network binding set by ConnectivityManager#bindProcessToNetwork. The socket must not be connected.

bindSocket

Added in API level 23
open fun bindSocket(fd: FileDescriptor!): Unit

Binds the specified FileDescriptor to this Network. All data traffic on the socket represented by this file descriptor will be sent on this Network, irrespective of any process-wide network binding set by ConnectivityManager#bindProcessToNetwork. The socket must not be connected.

describeContents

Added in API level 21
open 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

Added in API level 21
open fun equals(other: Any?): Boolean
Parameters
obj the reference object with which to compare.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

fromNetworkHandle

Added in API level 28
open static fun fromNetworkHandle(networkHandle: Long): Network!

Returns a Network object given a handle returned from getNetworkHandle.

Parameters
networkHandle Long: a handle returned from getNetworkHandle.
Return
Network! A Network object derived from networkHandle.

getAllByName

Added in API level 21
open fun getAllByName(host: String!): Array<InetAddress!>!

Operates the same as InetAddress.getAllByName except that host resolution is done on this network.

Parameters
host String!: the hostname or literal IP string to be resolved.
Return
Array<InetAddress!>! the array of addresses associated with the specified host.
Exceptions
java.net.UnknownHostException if the address lookup fails.

getByName

Added in API level 21
open fun getByName(host: String!): InetAddress!

Operates the same as InetAddress.getByName except that host resolution is done on this network.

Parameters
host String!: the hostname to be resolved to an address or null.
Return
InetAddress! the InetAddress instance representing the host.
Exceptions
java.net.UnknownHostException if the address lookup fails.

getNetworkHandle

Added in API level 23
open fun getNetworkHandle(): Long

Returns a handle representing this Network, for use with the NDK API.

getSocketFactory

Added in API level 21
open fun getSocketFactory(): SocketFactory!

Returns a SocketFactory bound to this network. Any Socket created by this factory will have its traffic sent over this Network. Note that if this Network ever disconnects, this factory and any Socket it produced in the past or future will cease to work.

Return
SocketFactory! a SocketFactory which produces Socket instances bound to this Network.

hashCode

Added in API level 21
open fun hashCode(): Int
Return
Int a hash code value for this object.

openConnection

Added in API level 21
open fun openConnection(url: URL!): URLConnection!

Opens the specified URL on this Network, such that all traffic will be sent on this Network. The URL protocol must be HTTP or HTTPS.

Return
URLConnection! a URLConnection to the resource referred to by this URL.
Exceptions
java.net.MalformedURLException if the URL protocol is not HTTP or HTTPS.
java.io.IOException if an error occurs while opening the connection.

openConnection

Added in API level 23
open fun openConnection(
    url: URL!,
    proxy: Proxy!
): URLConnection!

Opens the specified URL on this Network, such that all traffic will be sent on this Network. The URL protocol must be HTTP or HTTPS.

Parameters
proxy Proxy!: the proxy through which the connection will be established.
Return
URLConnection! a URLConnection to the resource referred to by this URL.
Exceptions
java.net.MalformedURLException if the URL protocol is not HTTP or HTTPS.
java.lang.IllegalArgumentException if the argument proxy is null.
java.io.IOException if an error occurs while opening the connection.

toString

Added in API level 21
open fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 21
open 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

Properties

CREATOR

Added in API level 21
static val CREATOR: Parcelable.Creator<Network!>