Skip to content

Most visited

Recently visited

navigation
Added in API level 1

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. Get an instance of this class by calling Context.getSystemService(Context.WIFI_SERVICE). It deals with several categories of items:

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.

Summary

Nested classes

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.

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 disableOthers)

Allow a previously configured network to be associated with.

List<WifiConfiguration> getConfiguredNetworks()

Return a list of all the networks configured in the supplicant.

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<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()

Check that the supplicant daemon is responding to requests.

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.

boolean saveConfiguration()

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

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.

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.
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.

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.

Parameters
netId int: the ID of the network as returned by addNetwork(WifiConfiguration).
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 disableOthers)

Allow a previously configured network to be associated with. If disableOthers is true, then all other configured networks are disabled, and 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.

Parameters
netId int: the ID of the network in the list of configured networks
disableOthers boolean: if true, disable all other networks. 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 in the supplicant. 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

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 ()

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.

Parameters
netId int: the integer that identifies the network configuration to the supplicant
Returns
boolean true if the operation succeeded

saveConfiguration

Added in API level 1
boolean saveConfiguration ()

Tell the supplicant 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).

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.
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 JavaTM 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.

Hooray!

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.