Skip to content

Most visited

Recently visited

navigation

WifiManager

public class WifiManager
extends Object

java.lang.Object
   ↳ android.net.wifi.WifiManager


This class provides the primary API for managing all aspects of Wi-Fi connectivity.

On releases before N, this object should only be obtained from an application context, and not from any other derived context to avoid memory leaks within the calling process.

It deals with several categories of items:

  • The list of configured networks. The list can be viewed and updated, and attributes of individual entries can be modified.
  • The currently active Wi-Fi network, if any. Connectivity can be established or torn down, and dynamic information about the state of the network can be queried.
  • Results of access point scans, containing enough information to make decisions about what access point to connect to.
  • It defines the names of various Intent actions that are broadcast upon any sort of change in Wi-Fi state.
This is the API to use when performing Wi-Fi specific operations. To perform operations that pertain to network connectivity at an abstract level, use ConnectivityManager.

Instances of this class must be obtained using Context.getSystemService(Class) with the argument WifiManager.class or Context.getSystemService(String) with the argument Context.WIFI_SERVICE.

Summary

Nested classes

class WifiManager.LocalOnlyHotspotCallback

Callback class for applications to receive updates about the LocalOnlyHotspot status. 

class WifiManager.LocalOnlyHotspotReservation

LocalOnlyHotspotReservation that contains the WifiConfiguration for the active LocalOnlyHotspot request. 

class WifiManager.MulticastLock

Allows an application to receive Wifi Multicast packets. 

class WifiManager.WifiLock

Allows an application to keep the Wi-Fi radio awake. 

class WifiManager.WpsCallback

Interface for callback invocation on a start WPS action  

Constants

String ACTION_PICK_WIFI_NETWORK

Activity Action: Pick a Wi-Fi network to connect to.

String ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE

Activity Action: Show a system activity that allows the user to enable scans to be available even with Wi-Fi turned off.

int ERROR_AUTHENTICATING

The error code if there was a problem authenticating.

String EXTRA_BSSID

The lookup key for a String giving the BSSID of the access point to which we are connected.

String EXTRA_NETWORK_INFO

The lookup key for a NetworkInfo object associated with the Wi-Fi network.

String EXTRA_NEW_RSSI

The lookup key for an int giving the new RSSI in dBm.

String EXTRA_NEW_STATE

The lookup key for a SupplicantState describing the new state Retrieve with getParcelableExtra(String).

String EXTRA_PREVIOUS_WIFI_STATE

The previous Wi-Fi state.

String EXTRA_RESULTS_UPDATED

Lookup key for a boolean representing the result of previous startScan() operation, reported with SCAN_RESULTS_AVAILABLE_ACTION.

String EXTRA_SUPPLICANT_CONNECTED

The lookup key for a boolean that indicates whether a connection to the supplicant daemon has been gained or lost.

String EXTRA_SUPPLICANT_ERROR

The lookup key for a SupplicantState describing the supplicant error code if any Retrieve with getIntExtra(String, int).

String EXTRA_WIFI_INFO

The lookup key for a WifiInfo object giving the information about the access point to which we are connected.

String EXTRA_WIFI_STATE

The lookup key for an int that indicates whether Wi-Fi is enabled, disabled, enabling, disabling, or unknown.

String NETWORK_IDS_CHANGED_ACTION

The network IDs of the configured networks could have changed.

String NETWORK_STATE_CHANGED_ACTION

Broadcast intent action indicating that the state of Wi-Fi connectivity has changed.

String RSSI_CHANGED_ACTION

The RSSI (signal strength) has changed.

String SCAN_RESULTS_AVAILABLE_ACTION

An access point scan has completed, and results are available from the supplicant.

String SUPPLICANT_CONNECTION_CHANGE_ACTION

Broadcast intent action indicating that a connection to the supplicant has been established (and it is now possible to perform Wi-Fi operations) or the connection to the supplicant has been lost.

String SUPPLICANT_STATE_CHANGED_ACTION

Broadcast intent action indicating that the state of establishing a connection to an access point has changed.One extra provides the new SupplicantState.

int WIFI_MODE_FULL

In this Wi-Fi lock mode, Wi-Fi will be kept active, and will behave normally, i.e., it will attempt to automatically establish a connection to a remembered access point that is within range, and will do periodic scans if there are remembered access points but none are in range.

int WIFI_MODE_FULL_HIGH_PERF

In this Wi-Fi lock mode, Wi-Fi will be kept active as in mode WIFI_MODE_FULL but it operates at high performance with minimum packet loss and low packet latency even when the device screen is off.

int WIFI_MODE_SCAN_ONLY

In this Wi-Fi lock mode, Wi-Fi will be kept active, but the only operation that will be supported is initiation of scans, and the subsequent reporting of scan results.

String WIFI_STATE_CHANGED_ACTION

Broadcast intent action indicating that Wi-Fi has been enabled, disabled, enabling, disabling, or unknown.

int WIFI_STATE_DISABLED

Wi-Fi is disabled.

int WIFI_STATE_DISABLING

Wi-Fi is currently being disabled.

int WIFI_STATE_ENABLED

Wi-Fi is enabled.

int WIFI_STATE_ENABLING

Wi-Fi is currently being enabled.

int WIFI_STATE_UNKNOWN

Wi-Fi is in an unknown state.

int WPS_AUTH_FAILURE

Authentication failure on WPS

int WPS_OVERLAP_ERROR

WPS overlap detected

int WPS_TIMED_OUT

WPS timed out

int WPS_TKIP_ONLY_PROHIBITED

TKIP only prohibited

int WPS_WEP_PROHIBITED

WEP on WPS is prohibited

Public methods

int addNetwork(WifiConfiguration config)

Add a new network description to the set of configured networks.

void addOrUpdatePasspointConfiguration(PasspointConfiguration config)

Add or update a Passpoint configuration.

static int calculateSignalLevel(int rssi, int numLevels)

Calculates the level of the signal.

void cancelWps(WifiManager.WpsCallback listener)

Cancel any ongoing Wi-fi Protected Setup

static int compareSignalLevel(int rssiA, int rssiB)

Compares two signal strengths.

WifiManager.MulticastLock createMulticastLock(String tag)

Create a new MulticastLock

WifiManager.WifiLock createWifiLock(String tag)

Creates a new WifiLock.

WifiManager.WifiLock createWifiLock(int lockType, String tag)

Creates a new WifiLock.

boolean disableNetwork(int netId)

Disable a configured network.

boolean disconnect()

Disassociate from the currently active access point.

boolean enableNetwork(int netId, boolean attemptConnect)

Allow a previously configured network to be associated with.

List<WifiConfiguration> getConfiguredNetworks()

Return a list of all the networks configured for the current foreground user.

WifiInfo getConnectionInfo()

Return dynamic information about the current Wi-Fi connection, if any is active.

DhcpInfo getDhcpInfo()

Return the DHCP-assigned addresses from the last successful DHCP request, if any.

List<PasspointConfiguration> getPasspointConfigurations()

Return the list of installed Passpoint configurations.

List<ScanResult> getScanResults()

Return the results of the latest access point scan.

int getWifiState()

Gets the Wi-Fi enabled state.

boolean is5GHzBandSupported()
boolean isDeviceToApRttSupported()
boolean isEnhancedPowerReportingSupported()
boolean isP2pSupported()
boolean isPreferredNetworkOffloadSupported()
boolean isScanAlwaysAvailable()

Check if scanning is always available.

boolean isTdlsSupported()
boolean isWifiEnabled()

Return whether Wi-Fi is enabled or disabled.

boolean pingSupplicant()

This method was deprecated in API level 26. Will return the output of isWifiEnabled() instead.

boolean reassociate()

Reconnect to the currently active access point, even if we are already connected.

boolean reconnect()

Reconnect to the currently active access point, if we are currently disconnected.

boolean removeNetwork(int netId)

Remove the specified network from the list of configured networks.

void removePasspointConfiguration(String fqdn)

Remove the Passpoint configuration identified by its FQDN (Fully Qualified Domain Name).

boolean saveConfiguration()

This method was deprecated in API level 26. There is no need to call this method - addNetwork(WifiConfiguration), updateNetwork(WifiConfiguration) and removeNetwork(int) already persist the configurations automatically.

void setTdlsEnabled(InetAddress remoteIPAddress, boolean enable)

Enable/Disable TDLS on a specific local route.

void setTdlsEnabledWithMacAddress(String remoteMacAddress, boolean enable)

Similar to setTdlsEnabled(InetAddress, boolean), except this version allows you to specify remote endpoint with a MAC address.

boolean setWifiEnabled(boolean enabled)

Enable or disable Wi-Fi.

void startLocalOnlyHotspot(WifiManager.LocalOnlyHotspotCallback callback, Handler handler)

Request a local only hotspot that an application can use to communicate between co-located devices connected to the created WiFi hotspot.

boolean startScan()

Request a scan for access points.

void startWps(WpsInfo config, WifiManager.WpsCallback listener)

Start Wi-fi Protected Setup

int updateNetwork(WifiConfiguration config)

Update the network description of an existing configured network.

Protected methods

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Inherited methods

From class java.lang.Object

Constants

ACTION_PICK_WIFI_NETWORK

added in API level 1
String ACTION_PICK_WIFI_NETWORK

Activity Action: Pick a Wi-Fi network to connect to.

Input: Nothing.

Output: Nothing.

Constant Value: "android.net.wifi.PICK_WIFI_NETWORK"

ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE

added in API level 18
String ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE

Activity Action: Show a system activity that allows the user to enable scans to be available even with Wi-Fi turned off.

Notification of the result of this activity is posted using the onActivityResult(int, int, Intent) callback. The resultCode will be RESULT_OK if scan always mode has been turned on or RESULT_CANCELED if the user has rejected the request or an error has occurred.

Constant Value: "android.net.wifi.action.REQUEST_SCAN_ALWAYS_AVAILABLE"

ERROR_AUTHENTICATING

added in API level 1
int ERROR_AUTHENTICATING

The error code if there was a problem authenticating.

Constant Value: 1 (0x00000001)

EXTRA_BSSID

added in API level 1
String EXTRA_BSSID

The lookup key for a String giving the BSSID of the access point to which we are connected. Only present when the new state is CONNECTED. Retrieve with getStringExtra(String).

Constant Value: "bssid"

EXTRA_NETWORK_INFO

added in API level 1
String EXTRA_NETWORK_INFO

The lookup key for a NetworkInfo object associated with the Wi-Fi network. Retrieve with getParcelableExtra(String).

Constant Value: "networkInfo"

EXTRA_NEW_RSSI

added in API level 1
String EXTRA_NEW_RSSI

The lookup key for an int giving the new RSSI in dBm.

Constant Value: "newRssi"

EXTRA_NEW_STATE

added in API level 1
String EXTRA_NEW_STATE

The lookup key for a SupplicantState describing the new state Retrieve with getParcelableExtra(String).

Constant Value: "newState"

EXTRA_PREVIOUS_WIFI_STATE

added in API level 1
String EXTRA_PREVIOUS_WIFI_STATE

The previous Wi-Fi state.

See also:

Constant Value: "previous_wifi_state"

EXTRA_RESULTS_UPDATED

added in API level 23
String EXTRA_RESULTS_UPDATED

Lookup key for a boolean representing the result of previous startScan() operation, reported with SCAN_RESULTS_AVAILABLE_ACTION.

Constant Value: "resultsUpdated"

EXTRA_SUPPLICANT_CONNECTED

added in API level 1
String EXTRA_SUPPLICANT_CONNECTED

The lookup key for a boolean that indicates whether a connection to the supplicant daemon has been gained or lost. true means a connection now exists. Retrieve it with getBooleanExtra(String, boolean).

Constant Value: "connected"

EXTRA_SUPPLICANT_ERROR

added in API level 1
String EXTRA_SUPPLICANT_ERROR

The lookup key for a SupplicantState describing the supplicant error code if any Retrieve with getIntExtra(String, int).

See also:

Constant Value: "supplicantError"

EXTRA_WIFI_INFO

added in API level 14
String EXTRA_WIFI_INFO

The lookup key for a WifiInfo object giving the information about the access point to which we are connected. Only present when the new state is CONNECTED. Retrieve with getParcelableExtra(String).

Constant Value: "wifiInfo"

EXTRA_WIFI_STATE

added in API level 1
String EXTRA_WIFI_STATE

The lookup key for an int that indicates whether Wi-Fi is enabled, disabled, enabling, disabling, or unknown. Retrieve it with getIntExtra(String, int).

See also:

Constant Value: "wifi_state"

NETWORK_IDS_CHANGED_ACTION

added in API level 1
String NETWORK_IDS_CHANGED_ACTION

The network IDs of the configured networks could have changed.

Constant Value: "android.net.wifi.NETWORK_IDS_CHANGED"

NETWORK_STATE_CHANGED_ACTION

added in API level 1
String NETWORK_STATE_CHANGED_ACTION

Broadcast intent action indicating that the state of Wi-Fi connectivity has changed. One extra provides the new state in the form of a NetworkInfo object. If the new state is CONNECTED, additional extras may provide the BSSID and WifiInfo of the access point. as a String.

See also:

Constant Value: "android.net.wifi.STATE_CHANGE"

RSSI_CHANGED_ACTION

added in API level 1
String RSSI_CHANGED_ACTION

The RSSI (signal strength) has changed.

See also:

Constant Value: "android.net.wifi.RSSI_CHANGED"

SCAN_RESULTS_AVAILABLE_ACTION

added in API level 1
String SCAN_RESULTS_AVAILABLE_ACTION

An access point scan has completed, and results are available from the supplicant. Call getScanResults() to obtain the results. EXTRA_RESULTS_UPDATED indicates if the scan was completed successfully.

Constant Value: "android.net.wifi.SCAN_RESULTS"

SUPPLICANT_CONNECTION_CHANGE_ACTION

added in API level 1
String SUPPLICANT_CONNECTION_CHANGE_ACTION

Broadcast intent action indicating that a connection to the supplicant has been established (and it is now possible to perform Wi-Fi operations) or the connection to the supplicant has been lost. One extra provides the connection state as a boolean, where true means CONNECTED.

See also:

Constant Value: "android.net.wifi.supplicant.CONNECTION_CHANGE"

SUPPLICANT_STATE_CHANGED_ACTION

added in API level 1
String SUPPLICANT_STATE_CHANGED_ACTION

Broadcast intent action indicating that the state of establishing a connection to an access point has changed.One extra provides the new SupplicantState. Note that the supplicant state is Wi-Fi specific, and is not generally the most useful thing to look at if you are just interested in the overall state of connectivity.

See also:

Constant Value: "android.net.wifi.supplicant.STATE_CHANGE"

WIFI_MODE_FULL

added in API level 3
int WIFI_MODE_FULL

In this Wi-Fi lock mode, Wi-Fi will be kept active, and will behave normally, i.e., it will attempt to automatically establish a connection to a remembered access point that is within range, and will do periodic scans if there are remembered access points but none are in range.

Constant Value: 1 (0x00000001)

WIFI_MODE_FULL_HIGH_PERF

added in API level 12
int WIFI_MODE_FULL_HIGH_PERF

In this Wi-Fi lock mode, Wi-Fi will be kept active as in mode WIFI_MODE_FULL but it operates at high performance with minimum packet loss and low packet latency even when the device screen is off. This mode will consume more power and hence should be used only when there is a need for such an active connection.

An example use case is when a voice connection needs to be kept active even after the device screen goes off. Holding the regular WIFI_MODE_FULL lock will keep the wifi connection active, but the connection can be lossy. Holding a WIFI_MODE_FULL_HIGH_PERF lock for the duration of the voice call will improve the call quality.

When there is no support from the hardware, this lock mode will have the same behavior as WIFI_MODE_FULL

Constant Value: 3 (0x00000003)

WIFI_MODE_SCAN_ONLY

added in API level 3
int WIFI_MODE_SCAN_ONLY

In this Wi-Fi lock mode, Wi-Fi will be kept active, but the only operation that will be supported is initiation of scans, and the subsequent reporting of scan results. No attempts will be made to automatically connect to remembered access points, nor will periodic scans be automatically performed looking for remembered access points. Scans must be explicitly requested by an application in this mode.

Constant Value: 2 (0x00000002)

WIFI_STATE_CHANGED_ACTION

added in API level 1
String WIFI_STATE_CHANGED_ACTION

Broadcast intent action indicating that Wi-Fi has been enabled, disabled, enabling, disabling, or unknown. One extra provides this state as an int. Another extra provides the previous state, if available.

See also:

Constant Value: "android.net.wifi.WIFI_STATE_CHANGED"

WIFI_STATE_DISABLED

added in API level 1
int WIFI_STATE_DISABLED

Wi-Fi is disabled.

See also:

Constant Value: 1 (0x00000001)

WIFI_STATE_DISABLING

added in API level 1
int WIFI_STATE_DISABLING

Wi-Fi is currently being disabled. The state will change to WIFI_STATE_DISABLED if it finishes successfully.

See also:

Constant Value: 0 (0x00000000)

WIFI_STATE_ENABLED

added in API level 1
int WIFI_STATE_ENABLED

Wi-Fi is enabled.

See also:

Constant Value: 3 (0x00000003)

WIFI_STATE_ENABLING

added in API level 1
int WIFI_STATE_ENABLING

Wi-Fi is currently being enabled. The state will change to WIFI_STATE_ENABLED if it finishes successfully.

See also:

Constant Value: 2 (0x00000002)

WIFI_STATE_UNKNOWN

added in API level 1
int WIFI_STATE_UNKNOWN

Wi-Fi is in an unknown state. This state will occur when an error happens while enabling or disabling.

See also:

Constant Value: 4 (0x00000004)

WPS_AUTH_FAILURE

added in API level 21
int WPS_AUTH_FAILURE

Authentication failure on WPS

Constant Value: 6 (0x00000006)

WPS_OVERLAP_ERROR

added in API level 21
int WPS_OVERLAP_ERROR

WPS overlap detected

Constant Value: 3 (0x00000003)

WPS_TIMED_OUT

added in API level 21
int WPS_TIMED_OUT

WPS timed out

Constant Value: 7 (0x00000007)

WPS_TKIP_ONLY_PROHIBITED

added in API level 21
int WPS_TKIP_ONLY_PROHIBITED

TKIP only prohibited

Constant Value: 5 (0x00000005)

WPS_WEP_PROHIBITED

added in API level 21
int WPS_WEP_PROHIBITED

WEP on WPS is prohibited

Constant Value: 4 (0x00000004)

Public methods

addNetwork

added in API level 1
int addNetwork (WifiConfiguration config)

Add a new network description to the set of configured networks. The networkId field of the supplied configuration object is ignored.

The new network will be marked DISABLED by default. To enable it, called enableNetwork(int, boolean).

Parameters
config WifiConfiguration: the set of variables that describe the configuration, contained in a WifiConfiguration object. If the WifiConfiguration has an Http Proxy set the calling app must be System, or be provisioned as the Profile or Device Owner.

Returns
int the ID of the newly created network description. This is used in other operations to specified the network to be acted upon. Returns -1 on failure.

addOrUpdatePasspointConfiguration

added in API level 26
void addOrUpdatePasspointConfiguration (PasspointConfiguration config)

Add or update a Passpoint configuration. The configuration provides a credential for connecting to Passpoint networks that are operated by the Passpoint service provider specified in the configuration. Each configuration is uniquely identified by its FQDN (Fully Qualified Domain Name). In the case when there is an existing configuration with the same FQDN, the new configuration will replace the existing configuration.

Parameters
config PasspointConfiguration: The Passpoint configuration to be added

Throws
IllegalArgumentException if configuration is invalid
UnsupportedOperationException if Passpoint is not enabled on the device.

calculateSignalLevel

added in API level 1
int calculateSignalLevel (int rssi, 
                int numLevels)

Calculates the level of the signal. This should be used any time a signal is being shown.

Parameters
rssi int: The power of the signal measured in RSSI.

numLevels int: The number of levels to consider in the calculated level.

Returns
int A level of the signal, given in the range of 0 to numLevels-1 (both inclusive).

cancelWps

added in API level 21
void cancelWps (WifiManager.WpsCallback listener)

Cancel any ongoing Wi-fi Protected Setup

Parameters
listener WifiManager.WpsCallback: for callbacks on success or failure. Can be null.

Throws
IllegalStateException if the WifiManager instance needs to be initialized again

compareSignalLevel

added in API level 1
int compareSignalLevel (int rssiA, 
                int rssiB)

Compares two signal strengths.

Parameters
rssiA int: The power of the first signal measured in RSSI.

rssiB int: The power of the second signal measured in RSSI.

Returns
int Returns <0 if the first signal is weaker than the second signal, 0 if the two signals have the same strength, and >0 if the first signal is stronger than the second signal.

createMulticastLock

added in API level 4
WifiManager.MulticastLock createMulticastLock (String tag)

Create a new MulticastLock

Parameters
tag String: a tag for the MulticastLock to identify it in debugging messages. This string is never shown to the user under normal conditions, but should be descriptive enough to identify your application and the specific MulticastLock within it, if it holds multiple MulticastLocks.

Returns
WifiManager.MulticastLock a new, unacquired MulticastLock with the given tag.

See also:

createWifiLock

added in API level 1
WifiManager.WifiLock createWifiLock (String tag)

Creates a new WifiLock.

Parameters
tag String: a tag for the WifiLock to identify it in debugging messages. This string is never shown to the user under normal conditions, but should be descriptive enough to identify your application and the specific WifiLock within it, if it holds multiple WifiLocks.

Returns
WifiManager.WifiLock a new, unacquired WifiLock with the given tag.

See also:

createWifiLock

added in API level 3
WifiManager.WifiLock createWifiLock (int lockType, 
                String tag)

Creates a new WifiLock.

Parameters
lockType int: the type of lock to create. See WIFI_MODE_FULL, WIFI_MODE_FULL_HIGH_PERF and WIFI_MODE_SCAN_ONLY for descriptions of the types of Wi-Fi locks.

tag String: a tag for the WifiLock to identify it in debugging messages. This string is never shown to the user under normal conditions, but should be descriptive enough to identify your application and the specific WifiLock within it, if it holds multiple WifiLocks.

Returns
WifiManager.WifiLock a new, unacquired WifiLock with the given tag.

See also:

disableNetwork

added in API level 1
boolean disableNetwork (int netId)

Disable a configured network. The specified network will not be a candidate for associating. This may result in the asynchronous delivery of state change events. Applications are not allowed to disable networks created by other applications.

Parameters
netId int: the ID of the network as returned by addNetwork(WifiConfiguration) or getConfiguredNetworks().

Returns
boolean true if the operation succeeded

disconnect

added in API level 1
boolean disconnect ()

Disassociate from the currently active access point. This may result in the asynchronous delivery of state change events.

Returns
boolean true if the operation succeeded

enableNetwork

added in API level 1
boolean enableNetwork (int netId, 
                boolean attemptConnect)

Allow a previously configured network to be associated with. If attemptConnect is true, an attempt to connect to the selected network is initiated. This may result in the asynchronous delivery of state change events.

Note: If an application's target SDK version is LOLLIPOP or newer, network communication may not use Wi-Fi even if Wi-Fi is connected; traffic may instead be sent through another network, such as cellular data, Bluetooth tethering, or Ethernet. For example, traffic will never use a Wi-Fi network that does not provide Internet access (e.g. a wireless printer), if another network that does offer Internet access (e.g. cellular data) is available. Applications that need to ensure that their network traffic uses Wi-Fi should use APIs such as bindSocket(java.net.Socket), openConnection(java.net.URL), or bindProcessToNetwork(Network) to do so. Applications are not allowed to enable networks created by other applications.

Parameters
netId int: the ID of the network as returned by addNetwork(WifiConfiguration) or getConfiguredNetworks().

attemptConnect boolean: The way to select a particular network to connect to is specify true for this parameter.

Returns
boolean true if the operation succeeded

getConfiguredNetworks

added in API level 1
List<WifiConfiguration> getConfiguredNetworks ()

Return a list of all the networks configured for the current foreground user. Not all fields of WifiConfiguration are returned. Only the following fields are filled in:

  • networkId
  • SSID
  • BSSID
  • priority
  • allowedProtocols
  • allowedKeyManagement
  • allowedAuthAlgorithms
  • allowedPairwiseCiphers
  • allowedGroupCiphers

Returns
List<WifiConfiguration> a list of network configurations in the form of a list of WifiConfiguration objects. Upon failure to fetch or when Wi-Fi is turned off, it can be null.

getConnectionInfo

added in API level 1
WifiInfo getConnectionInfo ()

Return dynamic information about the current Wi-Fi connection, if any is active.

Returns
WifiInfo the Wi-Fi information, contained in WifiInfo.

getDhcpInfo

added in API level 1
DhcpInfo getDhcpInfo ()

Return the DHCP-assigned addresses from the last successful DHCP request, if any.

Returns
DhcpInfo the DHCP information

getPasspointConfigurations

added in API level 26
List<PasspointConfiguration> getPasspointConfigurations ()

Return the list of installed Passpoint configurations. An empty list will be returned when no configurations are installed.

Returns
List<PasspointConfiguration> A list of PasspointConfiguration

Throws
UnsupportedOperationException if Passpoint is not enabled on the device.

getScanResults

added in API level 1
List<ScanResult> getScanResults ()

Return the results of the latest access point scan.

Returns
List<ScanResult> the list of access points found in the most recent scan. An app must hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in order to get valid results. If there is a remote exception (e.g., either a communication problem with the system service or an exception within the framework) an empty list will be returned.

getWifiState

added in API level 1
int getWifiState ()

Gets the Wi-Fi enabled state.

Returns
int One of WIFI_STATE_DISABLED, WIFI_STATE_DISABLING, WIFI_STATE_ENABLED, WIFI_STATE_ENABLING, WIFI_STATE_UNKNOWN

See also:

is5GHzBandSupported

added in API level 21
boolean is5GHzBandSupported ()

Returns
boolean true if this adapter supports 5 GHz band

isDeviceToApRttSupported

added in API level 21
boolean isDeviceToApRttSupported ()

Returns
boolean true if this adapter supports Device-to-AP RTT

isEnhancedPowerReportingSupported

added in API level 21
boolean isEnhancedPowerReportingSupported ()

Returns
boolean true if this adapter supports advanced power/performance counters

isP2pSupported

added in API level 21
boolean isP2pSupported ()

Returns
boolean true if this adapter supports WifiP2pManager (Wi-Fi Direct)

isPreferredNetworkOffloadSupported

added in API level 21
boolean isPreferredNetworkOffloadSupported ()

Returns
boolean true if this adapter supports offloaded connectivity scan

isScanAlwaysAvailable

added in API level 18
boolean isScanAlwaysAvailable ()

Check if scanning is always available. If this return true, apps can issue startScan() and fetch scan results even when Wi-Fi is turned off. To change this setting, see ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE.

Returns
boolean

isTdlsSupported

added in API level 21
boolean isTdlsSupported ()

Returns
boolean true if this adapter supports Tunnel Directed Link Setup

isWifiEnabled

added in API level 1
boolean isWifiEnabled ()

Return whether Wi-Fi is enabled or disabled.

Returns
boolean true if Wi-Fi is enabled

See also:

pingSupplicant

added in API level 1
boolean pingSupplicant ()

This method was deprecated in API level 26.
Will return the output of isWifiEnabled() instead.

Check that the supplicant daemon is responding to requests.

Returns
boolean true if we were able to communicate with the supplicant and it returned the expected response to the PING message.

reassociate

added in API level 1
boolean reassociate ()

Reconnect to the currently active access point, even if we are already connected. This may result in the asynchronous delivery of state change events.

Returns
boolean true if the operation succeeded

reconnect

added in API level 1
boolean reconnect ()

Reconnect to the currently active access point, if we are currently disconnected. This may result in the asynchronous delivery of state change events.

Returns
boolean true if the operation succeeded

removeNetwork

added in API level 1
boolean removeNetwork (int netId)

Remove the specified network from the list of configured networks. This may result in the asynchronous delivery of state change events. Applications are not allowed to remove networks created by other applications.

Parameters
netId int: the ID of the network as returned by addNetwork(WifiConfiguration) or getConfiguredNetworks().

Returns
boolean true if the operation succeeded

removePasspointConfiguration

added in API level 26
void removePasspointConfiguration (String fqdn)

Remove the Passpoint configuration identified by its FQDN (Fully Qualified Domain Name).

Parameters
fqdn String: The FQDN of the Passpoint configuration to be removed

Throws
IllegalArgumentException if no configuration is associated with the given FQDN.
UnsupportedOperationException if Passpoint is not enabled on the device.

saveConfiguration

added in API level 1
boolean saveConfiguration ()

This method was deprecated in API level 26.
There is no need to call this method - addNetwork(WifiConfiguration), updateNetwork(WifiConfiguration) and removeNetwork(int) already persist the configurations automatically.

Tell the device to persist the current list of configured networks.

Note: It is possible for this method to change the network IDs of existing networks. You should assume the network IDs can be different after calling this method.

Returns
boolean true if the operation succeeded

setTdlsEnabled

added in API level 19
void setTdlsEnabled (InetAddress remoteIPAddress, 
                boolean enable)

Enable/Disable TDLS on a specific local route.

TDLS enables two wireless endpoints to talk to each other directly without going through the access point that is managing the local network. It saves bandwidth and improves quality of the link.

This API enables/disables the option of using TDLS. If enabled, the underlying hardware is free to use TDLS or a hop through the access point. If disabled, existing TDLS session is torn down and hardware is restricted to use access point for transferring wireless packets. Default value for all routes is 'disabled', meaning restricted to use access point for transferring packets.

Parameters
remoteIPAddress InetAddress: IP address of the endpoint to setup TDLS with

enable boolean: true = setup and false = tear down TDLS

setTdlsEnabledWithMacAddress

added in API level 19
void setTdlsEnabledWithMacAddress (String remoteMacAddress, 
                boolean enable)

Similar to setTdlsEnabled(InetAddress, boolean), except this version allows you to specify remote endpoint with a MAC address.

Parameters
remoteMacAddress String: MAC address of the remote endpoint such as 00:00:0c:9f:f2:ab

enable boolean: true = setup and false = tear down TDLS

setWifiEnabled

added in API level 1
boolean setWifiEnabled (boolean enabled)

Enable or disable Wi-Fi.

Parameters
enabled boolean: true to enable, false to disable.

Returns
boolean true if the operation succeeds (or if the existing state is the same as the requested state).

startLocalOnlyHotspot

added in API level 26
void startLocalOnlyHotspot (WifiManager.LocalOnlyHotspotCallback callback, 
                Handler handler)

Request a local only hotspot that an application can use to communicate between co-located devices connected to the created WiFi hotspot. The network created by this method will not have Internet access. Each application can make a single request for the hotspot, but multiple applications could be requesting the hotspot at the same time. When multiple applications have successfully registered concurrently, they will be sharing the underlying hotspot. onStarted(LocalOnlyHotspotReservation) is called when the hotspot is ready for use by the application.

Each application can make a single active call to this method. The onStarted(LocalOnlyHotspotReservation) callback supplies the requestor with a WifiManager.LocalOnlyHotspotReservation that contains a WifiConfiguration with the SSID, security type and credentials needed to connect to the hotspot. Communicating this information is up to the application.

If the LocalOnlyHotspot cannot be created, the onFailed(int) method will be called. Example failures include errors bringing up the network or if there is an incompatible operating mode. For example, if the user is currently using Wifi Tethering to provide an upstream to another device, LocalOnlyHotspot will not start due to an incompatible mode. The possible error codes include: ERROR_NO_CHANNEL, ERROR_GENERIC, ERROR_INCOMPATIBLE_MODE and ERROR_TETHERING_DISALLOWED.

Internally, requests will be tracked to prevent the hotspot from being torn down while apps are still using it. The WifiManager.LocalOnlyHotspotReservation object passed in the onStarted(LocalOnlyHotspotReservation) call should be closed when the LocalOnlyHotspot is no longer needed using close(). Since the hotspot may be shared among multiple applications, removing the final registered application request will trigger the hotspot teardown. This means that applications should not listen to broadcasts containing wifi state to determine if the hotspot was stopped after they are done using it. Additionally, once close() is called, applications will not receive callbacks of any kind.

Applications should be aware that the user may also stop the LocalOnlyHotspot through the Settings UI; it is not guaranteed to stay up as long as there is a requesting application. The requestors will be notified of this case via onStopped(). Other cases may arise where the hotspot is torn down (Emergency mode, etc). Application developers should be aware that it can stop unexpectedly, but they will receive a notification if they have properly registered.

Applications should also be aware that this network will be shared with other applications. Applications are responsible for protecting their data on this network (e.g., TLS).

Applications need to have the following permissions to start LocalOnlyHotspot: CHANGE_WIFI_STATE and ACCESS_COARSE_LOCATION. Callers without the permissions will trigger a SecurityException.

Parameters
callback WifiManager.LocalOnlyHotspotCallback: LocalOnlyHotspotCallback for the application to receive updates about operating status.

handler Handler: Handler to be used for callbacks. If the caller passes a null Handler, the main thread will be used.

startScan

added in API level 1
boolean startScan ()

Request a scan for access points. Returns immediately. The availability of the results is made known later by means of an asynchronous event sent on completion of the scan.

Returns
boolean true if the operation succeeded, i.e., the scan was initiated

startWps

added in API level 21
void startWps (WpsInfo config, 
                WifiManager.WpsCallback listener)

Start Wi-fi Protected Setup

Parameters
config WpsInfo: WPS configuration (does not support LABEL)

listener WifiManager.WpsCallback: for callbacks on success or failure. Can be null.

Throws
IllegalStateException if the WifiManager instance needs to be initialized again

updateNetwork

added in API level 1
int updateNetwork (WifiConfiguration config)

Update the network description of an existing configured network.

Parameters
config WifiConfiguration: the set of variables that describe the configuration, contained in a WifiConfiguration object. It may be sparse, so that only the items that are being changed are non-null. The networkId field must be set to the ID of the existing network being updated. If the WifiConfiguration has an Http Proxy set the calling app must be System, or be provisioned as the Profile or Device Owner.

Returns
int Returns the networkId of the supplied WifiConfiguration on success.
Returns -1 on failure, including when the networkId field of the WifiConfiguration does not refer to an existing network.

Protected methods

finalize

added in API level 1
void finalize ()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the Java™ virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Throws
Throwable
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.