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 android.net.ConnectivityManager#requestNetwork or passive android.net.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?)

Indicates whether some other object is "equal to" this one.

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

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 return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj This value may be null.
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. This value cannot be null.
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!>