Added in API level 29

DnsResolver


class DnsResolver
kotlin.Any
   ↳ android.net.DnsResolver

Dns resolver class for asynchronous dns querying Note that if a client sends a query with more than 1 record in the question section but the remote dns server does not support this, it may not respond at all, leading to a timeout.

Summary

Nested classes
abstract

Base interface for answer callbacks

Class to represent DNS error

Constants
static Int

static Int

Indicates that there was an error parsing the response the query.

static Int

Indicates that there was an error sending the query.

static Int

static Int

static Int

static Int

static Int

static Int

Public methods
static DnsResolver

Get instance for DnsResolver

Unit
query(network: Network?, domain: String, flags: Int, executor: Executor, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<in MutableList<InetAddress!>!>)

Send a DNS query with the specified name on a network with both IPv4 and IPv6, get back a set of InetAddresses with rfc6724 sorting style asynchronously.

Unit
query(network: Network?, domain: String, nsType: Int, flags: Int, executor: Executor, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<in MutableList<InetAddress!>!>)

Send a DNS query with the specified name and query type, get back a set of InetAddresses with rfc6724 sorting style asynchronously.

Unit
rawQuery(network: Network?, query: ByteArray, flags: Int, executor: Executor, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<in ByteArray!>)

Send a raw DNS query.

Unit
rawQuery(network: Network?, domain: String, nsClass: Int, nsType: Int, flags: Int, executor: Executor, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<in ByteArray!>)

Send a DNS query with the specified name, class and query type.

Constants

CLASS_IN

Added in API level 29
static val CLASS_IN: Int
Value: 1

ERROR_PARSE

Added in API level 29
static val ERROR_PARSE: Int

Indicates that there was an error parsing the response the query. The cause of this error is available via getCause() and is a ParseException.

Value: 0

ERROR_SYSTEM

Added in API level 29
static val ERROR_SYSTEM: Int

Indicates that there was an error sending the query. The cause of this error is available via getCause() and is an ErrnoException.

Value: 1

FLAG_EMPTY

Added in API level 29
static val FLAG_EMPTY: Int
Value: 0

FLAG_NO_CACHE_LOOKUP

Added in API level 29
static val FLAG_NO_CACHE_LOOKUP: Int
Value: 4

FLAG_NO_CACHE_STORE

Added in API level 29
static val FLAG_NO_CACHE_STORE: Int
Value: 2

FLAG_NO_RETRY

Added in API level 29
static val FLAG_NO_RETRY: Int
Value: 1

TYPE_A

Added in API level 29
static val TYPE_A: Int
Value: 1

TYPE_AAAA

Added in API level 29
static val TYPE_AAAA: Int
Value: 28

Public methods

getInstance

Added in API level 29
static fun getInstance(): DnsResolver

Get instance for DnsResolver

Return
DnsResolver This value cannot be null.

query

Added in API level 29
fun query(
    network: Network?,
    domain: String,
    flags: Int,
    executor: Executor,
    cancellationSignal: CancellationSignal?,
    callback: DnsResolver.Callback<in MutableList<InetAddress!>!>
): Unit

Send a DNS query with the specified name on a network with both IPv4 and IPv6, get back a set of InetAddresses with rfc6724 sorting style asynchronously. This method will examine the connection ability on given network, and query IPv4 and IPv6 if connection is available. If at least one query succeeded with valid answer, rcode will be 0 The answer will be provided asynchronously through the provided Callback.

Parameters
network Network?: Network specifying which network to query on. null for query on default network.
domain String: domain name to query This value cannot be null.
flags Int: flags as a combination of the FLAGS_* constants Value is android.net.DnsResolver#FLAG_EMPTY, android.net.DnsResolver#FLAG_NO_RETRY, android.net.DnsResolver#FLAG_NO_CACHE_STORE, or android.net.DnsResolver#FLAG_NO_CACHE_LOOKUP
executor Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
cancellationSignal CancellationSignal?: used by the caller to signal if the query should be cancelled. May be null.
callback DnsResolver.Callback<in MutableList<InetAddress!>!>: a Callback which will be called to notify the caller of the result of dns query. This value cannot be null.

query

Added in API level 29
fun query(
    network: Network?,
    domain: String,
    nsType: Int,
    flags: Int,
    executor: Executor,
    cancellationSignal: CancellationSignal?,
    callback: DnsResolver.Callback<in MutableList<InetAddress!>!>
): Unit

Send a DNS query with the specified name and query type, get back a set of InetAddresses with rfc6724 sorting style asynchronously. The answer will be provided asynchronously through the provided Callback.

Parameters
network Network?: Network specifying which network to query on. null for query on default network.
domain String: domain name to query This value cannot be null.
nsType Int: dns resource record (RR) type as one of the TYPE_* constants Value is android.net.DnsResolver#TYPE_A, or android.net.DnsResolver#TYPE_AAAA
flags Int: flags as a combination of the FLAGS_* constants Value is android.net.DnsResolver#FLAG_EMPTY, android.net.DnsResolver#FLAG_NO_RETRY, android.net.DnsResolver#FLAG_NO_CACHE_STORE, or android.net.DnsResolver#FLAG_NO_CACHE_LOOKUP
executor Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
cancellationSignal CancellationSignal?: used by the caller to signal if the query should be cancelled. May be null.
callback DnsResolver.Callback<in MutableList<InetAddress!>!>: a Callback which will be called to notify the caller of the result of dns query. This value cannot be null.

rawQuery

Added in API level 29
fun rawQuery(
    network: Network?,
    query: ByteArray,
    flags: Int,
    executor: Executor,
    cancellationSignal: CancellationSignal?,
    callback: DnsResolver.Callback<in ByteArray!>
): Unit

Send a raw DNS query. The answer will be provided asynchronously through the provided Callback.

Parameters
network Network?: Network specifying which network to query on. null for query on default network.
query ByteArray: blob message to query This value cannot be null.
flags Int: flags as a combination of the FLAGS_* constants Value is android.net.DnsResolver#FLAG_EMPTY, android.net.DnsResolver#FLAG_NO_RETRY, android.net.DnsResolver#FLAG_NO_CACHE_STORE, or android.net.DnsResolver#FLAG_NO_CACHE_LOOKUP
executor Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
cancellationSignal CancellationSignal?: used by the caller to signal if the query should be cancelled. May be null.
callback DnsResolver.Callback<in ByteArray!>: a Callback which will be called to notify the caller of the result of dns query. This value cannot be null.

rawQuery

Added in API level 29
fun rawQuery(
    network: Network?,
    domain: String,
    nsClass: Int,
    nsType: Int,
    flags: Int,
    executor: Executor,
    cancellationSignal: CancellationSignal?,
    callback: DnsResolver.Callback<in ByteArray!>
): Unit

Send a DNS query with the specified name, class and query type. The answer will be provided asynchronously through the provided Callback.

Parameters
network Network?: Network specifying which network to query on. null for query on default network.
domain String: domain name to query This value cannot be null.
nsClass Int: dns class as one of the CLASS_* constants Value is android.net.DnsResolver#CLASS_IN
nsType Int: dns resource record (RR) type as one of the TYPE_* constants Value is android.net.DnsResolver#TYPE_A, or android.net.DnsResolver#TYPE_AAAA
flags Int: flags as a combination of the FLAGS_* constants Value is android.net.DnsResolver#FLAG_EMPTY, android.net.DnsResolver#FLAG_NO_RETRY, android.net.DnsResolver#FLAG_NO_CACHE_STORE, or android.net.DnsResolver#FLAG_NO_CACHE_LOOKUP
executor Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
cancellationSignal CancellationSignal?: used by the caller to signal if the query should be cancelled. May be null.
callback DnsResolver.Callback<in ByteArray!>: a Callback which will be called to notify the caller of the result of dns query. This value cannot be null.