public class WifiManager extends Object
Context.getSystemService(Context.WIFI_SERVICE)
.
On releases before NYC, it 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:
ConnectivityManager
.Modifier and Type | Class and Description |
---|---|
static interface |
WifiManager.ActionListener
Interface for callback invocation on an application action
|
class |
WifiManager.MulticastLock
Allows an application to receive Wifi Multicast packets.
|
static interface |
WifiManager.TxPacketCountListener
Interface for callback invocation on a TX packet count poll action
|
class |
WifiManager.WifiLock
Allows an application to keep the Wi-Fi radio awake.
|
static class |
WifiManager.WpsCallback
Interface for callback invocation on a start WPS action
|
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_PICK_WIFI_NETWORK
Activity Action: Pick a Wi-Fi network to connect to.
|
static 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.
|
static String |
BATCHED_SCAN_RESULTS_AVAILABLE_ACTION
Deprecated.
This API is nolonger supported.
Use
WifiScanner API |
static int |
BUSY
Passed with
WifiManager.ActionListener.onFailure(int) . |
static int |
CANCEL_WPS |
static int |
CANCEL_WPS_FAILED |
static int |
CANCEL_WPS_SUCCEDED |
static int |
CHANGE_REASON_ADDED
The configuration is new and was added.
|
static int |
CHANGE_REASON_CONFIG_CHANGE
The configuration has changed as a result of explicit action or because the system
took an automated action such as disabling a malfunctioning configuration.
|
static int |
CHANGE_REASON_REMOVED
The configuration was removed and is no longer present in the system's list of
configured networks.
|
static String |
CONFIGURED_NETWORKS_CHANGED_ACTION
Broadcast intent action indicating that the configured networks changed.
|
static int |
CONNECT_NETWORK |
static int |
CONNECT_NETWORK_FAILED |
static int |
CONNECT_NETWORK_SUCCEEDED |
static int |
DATA_ACTIVITY_IN |
static int |
DATA_ACTIVITY_INOUT |
static int |
DATA_ACTIVITY_NONE |
static int |
DATA_ACTIVITY_NOTIFICATION
List of asyncronous notifications
|
static int |
DATA_ACTIVITY_OUT |
static boolean |
DEFAULT_POOR_NETWORK_AVOIDANCE_ENABLED |
static int |
DISABLE_NETWORK |
static int |
DISABLE_NETWORK_FAILED |
static int |
DISABLE_NETWORK_SUCCEEDED |
static int |
ERROR
Passed with
WifiManager.ActionListener.onFailure(int) . |
static int |
ERROR_AUTHENTICATING
The error code if there was a problem authenticating.
|
static String |
EXTRA_BSSID
The lookup key for a String giving the BSSID of the access point to which
we are connected.
|
static String |
EXTRA_CHANGE_REASON
The lookup key for an integer indicating the reason a Wi-Fi network configuration
has changed.
|
static String |
EXTRA_LINK_PROPERTIES
The lookup key for a
LinkProperties object associated with the
Wi-Fi network. |
static String |
EXTRA_MULTIPLE_NETWORKS_CHANGED
Multiple network configurations have changed.
|
static String |
EXTRA_NETWORK_CAPABILITIES
The lookup key for a
NetworkCapabilities object associated with the
Wi-Fi network. |
static String |
EXTRA_NETWORK_INFO
The lookup key for a
NetworkInfo object associated with the
Wi-Fi network. |
static String |
EXTRA_NEW_RSSI
The lookup key for an
int giving the new RSSI in dBm. |
static String |
EXTRA_NEW_STATE
The lookup key for a
SupplicantState describing the new state
Retrieve with
Intent.getParcelableExtra(String) . |
static String |
EXTRA_PASSPOINT_ICON_BSSID |
static String |
EXTRA_PASSPOINT_ICON_DATA |
static String |
EXTRA_PASSPOINT_ICON_FILE |
static String |
EXTRA_PASSPOINT_WNM_BSSID
Originating BSS
|
static String |
EXTRA_PASSPOINT_WNM_DELAY
Delay in seconds
|
static String |
EXTRA_PASSPOINT_WNM_ESS
Boolean true=ess, false=bss
|
static String |
EXTRA_PASSPOINT_WNM_METHOD
SOAP-XML or OMA-DM
|
static String |
EXTRA_PASSPOINT_WNM_PPOINT_MATCH
Type of Passpoint match
|
static String |
EXTRA_PASSPOINT_WNM_URL
String
|
static String |
EXTRA_PREVIOUS_WIFI_AP_STATE
The previous Wi-Fi state.
|
static String |
EXTRA_PREVIOUS_WIFI_STATE
The previous Wi-Fi state.
|
static String |
EXTRA_RESULTS_UPDATED
Lookup key for a
boolean representing the result of previous startScan()
operation, reported with SCAN_RESULTS_AVAILABLE_ACTION . |
static String |
EXTRA_SCAN_AVAILABLE
Extra int indicating scan availability, WIFI_STATE_ENABLED and WIFI_STATE_DISABLED
|
static String |
EXTRA_SUPPLICANT_CONNECTED
The lookup key for a boolean that indicates whether a connection to
the supplicant daemon has been gained or lost.
|
static String |
EXTRA_SUPPLICANT_ERROR
The lookup key for a
SupplicantState describing the supplicant
error code if any
Retrieve with
Intent.getIntExtra(String, int) . |
static String |
EXTRA_WIFI_AP_FAILURE_REASON
The look up key for an int that indicates why softAP started failed
currently support general and no_channel
|
static String |
EXTRA_WIFI_AP_STATE
The lookup key for an int that indicates whether Wi-Fi AP is enabled,
disabled, enabling, disabling, or failed.
|
static String |
EXTRA_WIFI_CONFIGURATION
The lookup key for a (@link android.net.wifi.WifiConfiguration} object representing
the changed Wi-Fi configuration when the
CONFIGURED_NETWORKS_CHANGED_ACTION
broadcast is sent. |
static String |
EXTRA_WIFI_CREDENTIAL_EVENT_TYPE |
static String |
EXTRA_WIFI_CREDENTIAL_SSID |
static String |
EXTRA_WIFI_INFO
The lookup key for a
WifiInfo object giving the
information about the access point to which we are connected. |
static String |
EXTRA_WIFI_STATE
The lookup key for an int that indicates whether Wi-Fi is enabled,
disabled, enabling, disabling, or unknown.
|
static int |
FORGET_NETWORK |
static int |
FORGET_NETWORK_FAILED |
static int |
FORGET_NETWORK_SUCCEEDED |
static int |
IN_PROGRESS
Passed with
WifiManager.ActionListener.onFailure(int) . |
static int |
INVALID_ARGS
Passed with
WifiManager.ActionListener.onFailure(int) . |
static String |
LINK_CONFIGURATION_CHANGED_ACTION
Broadcast intent action indicating that the link configuration
changed on wifi.
|
static String |
NETWORK_IDS_CHANGED_ACTION
The network IDs of the configured networks could have changed.
|
static String |
NETWORK_STATE_CHANGED_ACTION
Broadcast intent action indicating that the state of Wi-Fi connectivity
has changed.
|
static int |
NOT_AUTHORIZED
Passed with
WifiManager.ActionListener.onFailure(int) . |
static String |
PASSPOINT_ICON_RECEIVED_ACTION
Broadcast intent action indicating that the a Passpoint release 2 icon has been received.
|
static String |
PASSPOINT_WNM_FRAME_RECEIVED_ACTION
Broadcast intent action indicating that the a Passpoint release
2 WNM frame has been received.
|
static String |
RSSI_CHANGED_ACTION
The RSSI (signal strength) has changed.
|
static int |
RSSI_LEVELS
Number of RSSI levels used in the framework to initiate
RSSI_CHANGED_ACTION broadcast |
static int |
RSSI_PKTCNT_FETCH |
static int |
RSSI_PKTCNT_FETCH_FAILED |
static int |
RSSI_PKTCNT_FETCH_SUCCEEDED |
static int |
SAP_START_FAILURE_GENERAL
If WIFI AP start failed, this reason code means there is no legal channel exists on
user selected band by regulatory
|
static int |
SAP_START_FAILURE_NO_CHANNEL
All other reason for AP start failed besides SAP_START_FAILURE_GENERAL
|
static int |
SAVE_NETWORK |
static int |
SAVE_NETWORK_FAILED |
static int |
SAVE_NETWORK_SUCCEEDED |
static String |
SCAN_RESULTS_AVAILABLE_ACTION
An access point scan has completed, and results are available from the supplicant.
|
static int |
START_WPS |
static int |
START_WPS_SUCCEEDED |
static 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.
|
static 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 . |
static String |
WIFI_AP_STATE_CHANGED_ACTION
Broadcast intent action indicating that Wi-Fi AP has been enabled, disabled,
enabling, disabling, or failed.
|
static int |
WIFI_AP_STATE_DISABLED
Wi-Fi AP is disabled.
|
static int |
WIFI_AP_STATE_DISABLING
Wi-Fi AP is currently being disabled.
|
static int |
WIFI_AP_STATE_ENABLED
Wi-Fi AP is enabled.
|
static int |
WIFI_AP_STATE_ENABLING
Wi-Fi AP is currently being enabled.
|
static int |
WIFI_AP_STATE_FAILED
Wi-Fi AP is in a failed state.
|
static String |
WIFI_CREDENTIAL_CHANGED_ACTION
Broadcast intent action indicating that the credential of a Wi-Fi network
has been changed.
|
static int |
WIFI_CREDENTIAL_FORGOT |
static int |
WIFI_CREDENTIAL_SAVED |
static int |
WIFI_FEATURE_ADDITIONAL_STA |
static int |
WIFI_FEATURE_AP_STA |
static int |
WIFI_FEATURE_BATCH_SCAN |
static int |
WIFI_FEATURE_D2AP_RTT |
static int |
WIFI_FEATURE_D2D_RTT |
static int |
WIFI_FEATURE_EPR |
static int |
WIFI_FEATURE_HAL_EPNO |
static int |
WIFI_FEATURE_INFRA |
static int |
WIFI_FEATURE_INFRA_5G |
static int |
WIFI_FEATURE_LINK_LAYER_STATS |
static int |
WIFI_FEATURE_LOGGER |
static int |
WIFI_FEATURE_MOBILE_HOTSPOT |
static int |
WIFI_FEATURE_NAN |
static int |
WIFI_FEATURE_P2P |
static int |
WIFI_FEATURE_PASSPOINT |
static int |
WIFI_FEATURE_PNO |
static int |
WIFI_FEATURE_SCANNER |
static int |
WIFI_FEATURE_TDLS |
static int |
WIFI_FEATURE_TDLS_OFFCHANNEL |
static int |
WIFI_FREQUENCY_BAND_2GHZ
Operation on 2.4 GHz alone
|
static int |
WIFI_FREQUENCY_BAND_5GHZ
Operation on 5 GHz alone
|
static int |
WIFI_FREQUENCY_BAND_AUTO
Auto settings in the driver.
|
static 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.
|
static 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. |
static int |
WIFI_MODE_NO_LOCKS_HELD
Internally used Wi-Fi lock mode representing the case were no locks are held.
|
static 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.
|
static String |
WIFI_SCAN_AVAILABLE
Broadcast intent action indicating whether Wi-Fi scanning is allowed currently
|
static String |
WIFI_STATE_CHANGED_ACTION
Broadcast intent action indicating that Wi-Fi has been enabled, disabled,
enabling, disabling, or unknown.
|
static int |
WIFI_STATE_DISABLED
Wi-Fi is disabled.
|
static int |
WIFI_STATE_DISABLING
Wi-Fi is currently being disabled.
|
static int |
WIFI_STATE_ENABLED
Wi-Fi is enabled.
|
static int |
WIFI_STATE_ENABLING
Wi-Fi is currently being enabled.
|
static int |
WIFI_STATE_UNKNOWN
Wi-Fi is in an unknown state.
|
static int |
WPS_AUTH_FAILURE
Authentication failure on WPS
|
static int |
WPS_COMPLETED |
static int |
WPS_FAILED |
static int |
WPS_OVERLAP_ERROR
WPS overlap detected
|
static int |
WPS_TIMED_OUT
WPS timed out
|
static int |
WPS_TKIP_ONLY_PROHIBITED
TKIP only prohibited
|
static int |
WPS_WEP_PROHIBITED
WEP on WPS is prohibited
|
Constructor and Description |
---|
WifiManager(Context context,
IWifiManager service,
Looper looper)
Create a new WifiManager instance.
|
Modifier and Type | Method and Description |
---|---|
int |
addNetwork(WifiConfiguration config)
Add a new network description to the set of configured networks.
|
int |
addPasspointManagementObject(String mo)
Add a Hotspot 2.0 release 2 Management Object
|
boolean |
addToBlacklist(String bssid)
Add a bssid to the supplicant blacklist
This API is used by WifiWatchdogService
|
WifiConfiguration |
buildWifiConfig(String uriString,
String mimeType,
byte[] data)
Builds a WifiConfiguration from Hotspot 2.0 MIME file.
|
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
|
boolean |
clearBlacklist()
Clear the supplicant blacklist
This API is used by WifiWatchdogService
|
static int |
compareSignalLevel(int rssiA,
int rssiB)
Compares two signal strengths.
|
void |
connect(int networkId,
WifiManager.ActionListener listener)
Connect to a network with the given networkId.
|
void |
connect(WifiConfiguration config,
WifiManager.ActionListener listener)
Connect to a network with the given configuration.
|
WifiManager.MulticastLock |
createMulticastLock(String tag)
Create a new MulticastLock
|
WifiManager.WifiLock |
createWifiLock(int lockType,
String tag)
Creates a new WifiLock.
|
WifiManager.WifiLock |
createWifiLock(String tag)
Creates a new WifiLock.
|
void |
deauthenticateNetwork(long holdoff,
boolean ess)
Deauthenticate and set the re-authentication hold off time for the current network
|
void |
disable(int netId,
WifiManager.ActionListener listener)
Disable network
|
void |
disableEphemeralNetwork(String SSID)
Disable ephemeral Network
|
boolean |
disableNetwork(int netId)
Disable a configured network.
|
boolean |
disconnect()
Disassociate from the currently active access point.
|
void |
enableAggressiveHandover(int enabled)
Set wifi Aggressive Handover.
|
boolean |
enableNetwork(int netId,
boolean disableOthers)
Allow a previously configured network to be associated with.
|
void |
enableVerboseLogging(int verbose)
Set wifi verbose log.
|
void |
enableWifiConnectivityManager(boolean enabled)
Enable/disable WifiConnectivityManager
|
void |
factoryReset()
Resets all wifi manager settings back to factory defaults.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
void |
forget(int netId,
WifiManager.ActionListener listener)
Delete the network in the supplicant config.
|
int |
getAggressiveHandover()
Get the WiFi Handover aggressiveness.This is used by settings
to decide what to show within the picker.
|
int |
getAllowScansWithTraffic()
Get setting for allowing Scans when traffic is ongoing.
|
List<BatchedScanResult> |
getBatchedScanResults()
Deprecated.
This API is nolonger supported.
Use
WifiScanner API |
String |
getConfigFile()
Returns the file in which IP and proxy configuration data is stored
|
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.
|
WifiConnectionStatistics |
getConnectionStatistics() |
WifiActivityEnergyInfo |
getControllerActivityEnergyInfo(int updateType)
Return the record of
WifiActivityEnergyInfo object that
has the activity and energy info. |
String |
getCountryCode()
get the country code.
|
Network |
getCurrentNetwork()
Get Network object of current wifi network
|
DhcpInfo |
getDhcpInfo()
Return the DHCP-assigned addresses from the last successful DHCP request,
if any.
|
boolean |
getEnableAutoJoinWhenAssociated()
Get setting for Framework layer autojoin enable status
|
int |
getFrequencyBand()
Get the operational frequency band.
|
WifiConfiguration |
getMatchingWifiConfig(ScanResult scanResult)
Returns a WifiConfiguration matching this ScanResult
|
List<WifiConfiguration> |
getPrivilegedConfiguredNetworks() |
List<ScanResult> |
getScanResults()
Return the results of the latest access point scan.
|
void |
getTxPacketCount(WifiManager.TxPacketCountListener listener)
Return TX packet counter, for CTS test of WiFi watchdog.
|
int |
getVerboseLoggingLevel()
Get the WiFi verbose logging level.This is used by settings
to decide what to show within the picker.
|
WifiConfiguration |
getWifiApConfiguration()
Gets the Wi-Fi AP Configuration.
|
int |
getWifiApState()
Gets the Wi-Fi enabled state.
|
Messenger |
getWifiServiceMessenger()
Get a reference to WifiService handler.
|
int |
getWifiState()
Gets the Wi-Fi enabled state.
|
String |
getWpsNfcConfigurationToken(int netId)
Creates a configuration token describing the network referenced by
netId
of MIME type application/vnd.wfa.wsc. |
boolean |
initializeMulticastFiltering()
Initialize the multicast filtering to 'on'
|
boolean |
is5GHzBandSupported() |
boolean |
isAdditionalStaSupported() |
boolean |
isBatchedScanSupported()
Deprecated.
This API is nolonger supported.
Use
WifiScanner API |
boolean |
isDeviceToApRttSupported() |
boolean |
isDeviceToDeviceRttSupported() |
boolean |
isDualBandSupported()
Check if the chipset supports dual frequency band (2.4 GHz and 5 GHz)
|
boolean |
isEnhancedPowerReportingSupported() |
boolean |
isMulticastEnabled()
Check multicast filter status.
|
boolean |
isNanSupported() |
boolean |
isOffChannelTdlsSupported() |
boolean |
isP2pSupported() |
boolean |
isPasspointSupported() |
boolean |
isPortableHotspotSupported() |
boolean |
isPreferredNetworkOffloadSupported() |
boolean |
isScanAlwaysAvailable()
Check if scanning is always available.
|
boolean |
isTdlsSupported() |
boolean |
isWifiApEnabled()
Return whether Wi-Fi AP is enabled or disabled.
|
boolean |
isWifiEnabled()
Return whether Wi-Fi is enabled or disabled.
|
boolean |
isWifiScannerSupported() |
int |
matchProviderWithCurrentNetwork(String fqdn)
Match the currently associated network against the SP matching the given FQDN
|
int |
modifyPasspointManagementObject(String fqdn,
List<PasspointManagementObjectDefinition> mos)
Modify a Hotspot 2.0 release 2 Management Object
|
boolean |
pingSupplicant()
Check that the supplicant daemon is responding to requests.
|
void |
queryPasspointIcon(long bssid,
String fileName)
Query for a Hotspot 2.0 release 2 OSU icon
|
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 |
save(WifiConfiguration config,
WifiManager.ActionListener listener)
Save the given network in the supplicant config.
|
boolean |
saveConfiguration()
Tell the supplicant to persist the current list of configured networks.
|
void |
setAllowScansWithTraffic(int enabled)
Set setting for allowing Scans when traffic is ongoing.
|
void |
setCountryCode(String country,
boolean persist)
Set the country code.
|
boolean |
setEnableAutoJoinWhenAssociated(boolean enabled)
Framework layer autojoin enable/disable when device is associated
this will enable/disable autojoin scan and switch network when connected
|
void |
setFrequencyBand(int band,
boolean persist)
Set the operational frequency band.
|
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 |
setWifiApConfiguration(WifiConfiguration wifiConfig)
Sets the Wi-Fi AP Configuration.
|
boolean |
setWifiApEnabled(WifiConfiguration wifiConfig,
boolean enabled)
Start AccessPoint mode with the specified
configuration.
|
boolean |
setWifiEnabled(boolean enabled)
Enable or disable Wi-Fi.
|
boolean |
startLocationRestrictedScan(WorkSource workSource)
Deprecated.
This API is nolonger supported.
Use
WifiScanner API |
boolean |
startScan()
Request a scan for access points.
|
boolean |
startScan(WorkSource workSource) |
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.
|
public static final int ERROR_AUTHENTICATING
public static final String WIFI_SCAN_AVAILABLE
public static final String EXTRA_SCAN_AVAILABLE
public static final String WIFI_CREDENTIAL_CHANGED_ACTION
public static final String EXTRA_WIFI_CREDENTIAL_EVENT_TYPE
public static final String EXTRA_WIFI_CREDENTIAL_SSID
public static final int WIFI_CREDENTIAL_SAVED
public static final int WIFI_CREDENTIAL_FORGOT
public static final String PASSPOINT_ICON_RECEIVED_ACTION
public static final String EXTRA_PASSPOINT_ICON_BSSID
public static final String EXTRA_PASSPOINT_ICON_FILE
public static final String EXTRA_PASSPOINT_ICON_DATA
public static final String PASSPOINT_WNM_FRAME_RECEIVED_ACTION
public static final String EXTRA_PASSPOINT_WNM_BSSID
public static final String EXTRA_PASSPOINT_WNM_METHOD
public static final String EXTRA_PASSPOINT_WNM_PPOINT_MATCH
public static final String EXTRA_PASSPOINT_WNM_URL
public static final String EXTRA_PASSPOINT_WNM_ESS
public static final String EXTRA_PASSPOINT_WNM_DELAY
public static final String WIFI_STATE_CHANGED_ACTION
public static final String EXTRA_WIFI_STATE
Intent.getIntExtra(String,int)
.public static final String EXTRA_PREVIOUS_WIFI_STATE
EXTRA_WIFI_STATE
,
Constant Field Valuespublic static final int WIFI_STATE_DISABLING
WIFI_STATE_DISABLED
if
it finishes successfully.public static final int WIFI_STATE_DISABLED
public static final int WIFI_STATE_ENABLING
WIFI_STATE_ENABLED
if
it finishes successfully.public static final int WIFI_STATE_ENABLED
public static final int WIFI_STATE_UNKNOWN
public static final String WIFI_AP_STATE_CHANGED_ACTION
public static final String EXTRA_WIFI_AP_STATE
Intent.getIntExtra(String,int)
.public static final String EXTRA_WIFI_AP_FAILURE_REASON
public static final String EXTRA_PREVIOUS_WIFI_AP_STATE
EXTRA_WIFI_AP_STATE
,
Constant Field Valuespublic static final int WIFI_AP_STATE_DISABLING
WIFI_AP_STATE_DISABLED
if it finishes successfully.public static final int WIFI_AP_STATE_DISABLED
public static final int WIFI_AP_STATE_ENABLING
WIFI_AP_STATE_ENABLED
if it finishes successfully.public static final int WIFI_AP_STATE_ENABLED
public static final int WIFI_AP_STATE_FAILED
public static final int SAP_START_FAILURE_GENERAL
public static final int SAP_START_FAILURE_NO_CHANNEL
public static final String SUPPLICANT_CONNECTION_CHANGE_ACTION
true
means CONNECTED.EXTRA_SUPPLICANT_CONNECTED
,
Constant Field Valuespublic static final String EXTRA_SUPPLICANT_CONNECTED
true
means
a connection now exists.
Retrieve it with Intent.getBooleanExtra(String,boolean)
.public static final String NETWORK_STATE_CHANGED_ACTION
NetworkInfo
object. If the new
state is CONNECTED, additional extras may provide the BSSID and WifiInfo of
the access point.
as a String
.public static final String EXTRA_NETWORK_INFO
NetworkInfo
object associated with the
Wi-Fi network. Retrieve with
Intent.getParcelableExtra(String)
.public static final String EXTRA_BSSID
Intent.getStringExtra(String)
.public static final String EXTRA_WIFI_INFO
WifiInfo
object giving the
information about the access point to which we are connected. Only present
when the new state is CONNECTED. Retrieve with
Intent.getParcelableExtra(String)
.public static final String SUPPLICANT_STATE_CHANGED_ACTION
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.public static final String EXTRA_NEW_STATE
SupplicantState
describing the new state
Retrieve with
Intent.getParcelableExtra(String)
.public static final String EXTRA_SUPPLICANT_ERROR
SupplicantState
describing the supplicant
error code if any
Retrieve with
Intent.getIntExtra(String, int)
.ERROR_AUTHENTICATING
,
Constant Field Valuespublic static final String CONFIGURED_NETWORKS_CHANGED_ACTION
EXTRA_MULTIPLE_NETWORKS_CHANGED
is set to true the new configuration
can be retreived with the EXTRA_WIFI_CONFIGURATION
extra. If multiple
Wi-Fi configurations changed, EXTRA_WIFI_CONFIGURATION
will not be present.public static final String EXTRA_WIFI_CONFIGURATION
CONFIGURED_NETWORKS_CHANGED_ACTION
broadcast is sent.public static final String EXTRA_MULTIPLE_NETWORKS_CHANGED
public static final String EXTRA_CHANGE_REASON
EXTRA_MULTIPLE_NETWORKS_CHANGED
is false
public static final int CHANGE_REASON_ADDED
public static final int CHANGE_REASON_REMOVED
public static final int CHANGE_REASON_CONFIG_CHANGE
public static final String SCAN_RESULTS_AVAILABLE_ACTION
getScanResults()
to obtain the results. EXTRA_RESULTS_UPDATED
indicates if the scan was completed successfully.public static final String EXTRA_RESULTS_UPDATED
boolean
representing the result of previous startScan()
operation, reported with SCAN_RESULTS_AVAILABLE_ACTION
.@Deprecated public static final String BATCHED_SCAN_RESULTS_AVAILABLE_ACTION
WifiScanner
APIgetBatchedScanResults()
to obtain the results.public static final String RSSI_CHANGED_ACTION
EXTRA_NEW_RSSI
,
Constant Field Valuespublic static final String EXTRA_NEW_RSSI
int
giving the new RSSI in dBm.public static final String LINK_CONFIGURATION_CHANGED_ACTION
public static final String EXTRA_LINK_PROPERTIES
LinkProperties
object associated with the
Wi-Fi network. Retrieve with
Intent.getParcelableExtra(String)
.public static final String EXTRA_NETWORK_CAPABILITIES
NetworkCapabilities
object associated with the
Wi-Fi network. Retrieve with
Intent.getParcelableExtra(String)
.public static final String NETWORK_IDS_CHANGED_ACTION
public static final String ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE
Notification of the result of this activity is posted using the
Activity.onActivityResult(int, int, android.content.Intent)
callback. The
resultCode
will be Activity.RESULT_OK
if scan always mode has
been turned on or Activity.RESULT_CANCELED
if the user
has rejected the request or an error has occurred.
public static final String ACTION_PICK_WIFI_NETWORK
Input: Nothing.
Output: Nothing.
public static final int WIFI_MODE_NO_LOCKS_HELD
public static final int WIFI_MODE_FULL
public static final int WIFI_MODE_SCAN_ONLY
public static final int WIFI_MODE_FULL_HIGH_PERF
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
public static final int RSSI_LEVELS
RSSI_CHANGED_ACTION
broadcastpublic static final int WIFI_FREQUENCY_BAND_AUTO
public static final int WIFI_FREQUENCY_BAND_5GHZ
public static final int WIFI_FREQUENCY_BAND_2GHZ
public static final int DATA_ACTIVITY_NOTIFICATION
public static final int DATA_ACTIVITY_NONE
public static final int DATA_ACTIVITY_IN
public static final int DATA_ACTIVITY_OUT
public static final int DATA_ACTIVITY_INOUT
public static final boolean DEFAULT_POOR_NETWORK_AVOIDANCE_ENABLED
public static final int WIFI_FEATURE_INFRA
public static final int WIFI_FEATURE_INFRA_5G
public static final int WIFI_FEATURE_PASSPOINT
public static final int WIFI_FEATURE_P2P
public static final int WIFI_FEATURE_MOBILE_HOTSPOT
public static final int WIFI_FEATURE_SCANNER
public static final int WIFI_FEATURE_NAN
public static final int WIFI_FEATURE_D2D_RTT
public static final int WIFI_FEATURE_D2AP_RTT
public static final int WIFI_FEATURE_BATCH_SCAN
public static final int WIFI_FEATURE_PNO
public static final int WIFI_FEATURE_ADDITIONAL_STA
public static final int WIFI_FEATURE_TDLS
public static final int WIFI_FEATURE_TDLS_OFFCHANNEL
public static final int WIFI_FEATURE_EPR
public static final int WIFI_FEATURE_AP_STA
public static final int WIFI_FEATURE_LINK_LAYER_STATS
public static final int WIFI_FEATURE_LOGGER
public static final int WIFI_FEATURE_HAL_EPNO
public static final int CONNECT_NETWORK
public static final int CONNECT_NETWORK_FAILED
public static final int CONNECT_NETWORK_SUCCEEDED
public static final int FORGET_NETWORK
public static final int FORGET_NETWORK_FAILED
public static final int FORGET_NETWORK_SUCCEEDED
public static final int SAVE_NETWORK
public static final int SAVE_NETWORK_FAILED
public static final int SAVE_NETWORK_SUCCEEDED
public static final int START_WPS
public static final int START_WPS_SUCCEEDED
public static final int WPS_FAILED
public static final int WPS_COMPLETED
public static final int CANCEL_WPS
public static final int CANCEL_WPS_FAILED
public static final int CANCEL_WPS_SUCCEDED
public static final int DISABLE_NETWORK
public static final int DISABLE_NETWORK_FAILED
public static final int DISABLE_NETWORK_SUCCEEDED
public static final int RSSI_PKTCNT_FETCH
public static final int RSSI_PKTCNT_FETCH_SUCCEEDED
public static final int RSSI_PKTCNT_FETCH_FAILED
public static final int ERROR
WifiManager.ActionListener.onFailure(int)
.
Indicates that the operation failed due to an internal error.public static final int IN_PROGRESS
WifiManager.ActionListener.onFailure(int)
.
Indicates that the operation is already in progresspublic static final int BUSY
WifiManager.ActionListener.onFailure(int)
.
Indicates that the operation failed because the framework is busy and
unable to service the requestpublic static final int WPS_OVERLAP_ERROR
public static final int WPS_WEP_PROHIBITED
public static final int WPS_TKIP_ONLY_PROHIBITED
public static final int WPS_AUTH_FAILURE
public static final int WPS_TIMED_OUT
public static final int INVALID_ARGS
WifiManager.ActionListener.onFailure(int)
.
Indicates that the operation failed due to invalid inputspublic static final int NOT_AUTHORIZED
WifiManager.ActionListener.onFailure(int)
.
Indicates that the operation failed due to user permissions.public WifiManager(Context context, IWifiManager service, Looper looper)
Context.getSystemService()
to retrieve
the standard Context.WIFI_SERVICE
.context
- the application contextservice
- the Binder interfacepublic List<WifiConfiguration> getConfiguredNetworks()
WifiConfiguration
objects. Upon failure to fetch or
when Wi-Fi is turned off, it can be null.public List<WifiConfiguration> getPrivilegedConfiguredNetworks()
public WifiConnectionStatistics getConnectionStatistics()
public WifiConfiguration getMatchingWifiConfig(ScanResult scanResult)
scanResult
- scanResult that represents the BSSIDWifiConfiguration
that matches this BSSID or nullpublic int addNetwork(WifiConfiguration config)
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)
.config
- the set of variables that describe the configuration,
contained in a WifiConfiguration
object.-1
on failure.public int updateNetwork(WifiConfiguration config)
config
- 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.networkId
of the supplied
WifiConfiguration
on success.
-1
on failure, including when the networkId
field of the WifiConfiguration
does not refer to an
existing network.public int addPasspointManagementObject(String mo)
mo
- The MO in XML formpublic int modifyPasspointManagementObject(String fqdn, List<PasspointManagementObjectDefinition> mos)
fqdn
- The FQDN of the service providermos
- A List of MO definitions to be updatedpublic void queryPasspointIcon(long bssid, String fileName)
bssid
- The BSSID of the APfileName
- Icon file namepublic int matchProviderWithCurrentNetwork(String fqdn)
fqdn
- FQDN of the SPpublic void deauthenticateNetwork(long holdoff, boolean ess)
holdoff
- hold off time in millisecondsess
- set if the hold off pertains to an ESS rather than a BSSpublic boolean removeNetwork(int netId)
netId
- the integer that identifies the network configuration
to the supplicanttrue
if the operation succeededpublic boolean enableNetwork(int netId, boolean disableOthers)
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
Build.VERSION_CODES.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
Network.bindSocket(java.net.Socket)
,
Network.openConnection(java.net.URL)
, or
ConnectivityManager.bindProcessToNetwork(android.net.Network)
to do so.
netId
- the ID of the network in the list of configured networksdisableOthers
- if true, disable all other networks. The way to
select a particular network to connect to is specify true
for this parameter.true
if the operation succeededpublic boolean disableNetwork(int netId)
netId
- the ID of the network as returned by addNetwork(android.net.wifi.WifiConfiguration)
.true
if the operation succeededpublic boolean disconnect()
true
if the operation succeededpublic boolean reconnect()
true
if the operation succeededpublic boolean reassociate()
true
if the operation succeededpublic boolean pingSupplicant()
true
if we were able to communicate with the supplicant and
it returned the expected response to the PING message.public boolean is5GHzBandSupported()
public boolean isPasspointSupported()
public boolean isP2pSupported()
public boolean isPortableHotspotSupported()
public boolean isWifiScannerSupported()
public boolean isNanSupported()
public boolean isDeviceToDeviceRttSupported()
public boolean isDeviceToApRttSupported()
public boolean isPreferredNetworkOffloadSupported()
public boolean isAdditionalStaSupported()
public boolean isTdlsSupported()
public boolean isOffChannelTdlsSupported()
public boolean isEnhancedPowerReportingSupported()
public WifiActivityEnergyInfo getControllerActivityEnergyInfo(int updateType)
WifiActivityEnergyInfo
object that
has the activity and energy info. This can be used to ascertain what
the controller has been up to, since the last sample.updateType
- Type of info, cached vs refreshed.WifiActivityEnergyInfo
or null if
report is unavailable or unsupportedpublic boolean startScan()
true
if the operation succeeded, i.e., the scan was initiatedpublic boolean startScan(WorkSource workSource)
@Deprecated public boolean startLocationRestrictedScan(WorkSource workSource)
WifiScanner
API@Deprecated public boolean isBatchedScanSupported()
WifiScanner
API@Deprecated public List<BatchedScanResult> getBatchedScanResults()
WifiScanner
APIBATCHED_SCAN_RESULTS_AVAILABLE_ACTION
is received.public String getWpsNfcConfigurationToken(int netId)
netId
of MIME type application/vnd.wfa.wsc. Can be used to configure WiFi networks via NFC.public WifiInfo getConnectionInfo()
WifiInfo
.public List<ScanResult> getScanResults()
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.public boolean isScanAlwaysAvailable()
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
.public boolean saveConfiguration()
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.
true
if the operation succeededpublic void setCountryCode(String country, boolean persist)
countryCode
- country code in ISO 3166 format.persist
- true
if this needs to be rememberedpublic String getCountryCode()
public void setFrequencyBand(int band, boolean persist)
band
- One of
WIFI_FREQUENCY_BAND_AUTO
,
WIFI_FREQUENCY_BAND_5GHZ
,
WIFI_FREQUENCY_BAND_2GHZ
,persist
- true
if this needs to be rememberedpublic int getFrequencyBand()
WIFI_FREQUENCY_BAND_AUTO
,
WIFI_FREQUENCY_BAND_5GHZ
,
WIFI_FREQUENCY_BAND_2GHZ
or
-1
on failure.public boolean isDualBandSupported()
true
if supported, false
otherwise.public DhcpInfo getDhcpInfo()
public boolean setWifiEnabled(boolean enabled)
enabled
- true
to enable, false
to disable.true
if the operation succeeds (or if the existing state
is the same as the requested state).public int getWifiState()
WIFI_STATE_DISABLED
,
WIFI_STATE_DISABLING
, WIFI_STATE_ENABLED
,
WIFI_STATE_ENABLING
, WIFI_STATE_UNKNOWN
isWifiEnabled()
public boolean isWifiEnabled()
true
if Wi-Fi is enabledgetWifiState()
public void getTxPacketCount(WifiManager.TxPacketCountListener listener)
listener
- is the interface to receive resultpublic static int calculateSignalLevel(int rssi, int numLevels)
rssi
- The power of the signal measured in RSSI.numLevels
- The number of levels to consider in the calculated
level.public static int compareSignalLevel(int rssiA, int rssiB)
rssiA
- The power of the first signal measured in RSSI.rssiB
- The power of the second signal measured in RSSI.public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled)
wifiConfig
- SSID, security and channel details as
part of WifiConfigurationtrue
if the operation succeeds, false
otherwisepublic int getWifiApState()
WIFI_AP_STATE_DISABLED
,
WIFI_AP_STATE_DISABLING
, WIFI_AP_STATE_ENABLED
,
WIFI_AP_STATE_ENABLING
, WIFI_AP_STATE_FAILED
isWifiApEnabled()
public boolean isWifiApEnabled()
true
if Wi-Fi AP is enabledgetWifiApState()
public WifiConfiguration getWifiApConfiguration()
public WifiConfiguration buildWifiConfig(String uriString, String mimeType, byte[] data)
public boolean setWifiApConfiguration(WifiConfiguration wifiConfig)
true
if the operation succeeded, false
otherwisepublic boolean addToBlacklist(String bssid)
true
if the operation succeeds else false
public boolean clearBlacklist()
true
if the operation succeeds else false
public void setTdlsEnabled(InetAddress remoteIPAddress, boolean enable)
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.
remoteIPAddress
- IP address of the endpoint to setup TDLS withenable
- true = setup and false = tear down TDLSpublic void setTdlsEnabledWithMacAddress(String remoteMacAddress, boolean enable)
setTdlsEnabled(InetAddress, boolean)
, except
this version allows you to specify remote endpoint with a MAC address.remoteMacAddress
- MAC address of the remote endpoint such as 00:00:0c:9f:f2:abenable
- true = setup and false = tear down TDLSpublic void connect(WifiConfiguration config, WifiManager.ActionListener listener)
config
- the set of variables that describe the configuration,
contained in a WifiConfiguration
object.listener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic void connect(int networkId, WifiManager.ActionListener listener)
networkId
- the network id identifiying the network in the
supplicant configuration listlistener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic void save(WifiConfiguration config, WifiManager.ActionListener listener)
config
- the set of variables that describe the configuration,
contained in a WifiConfiguration
object.listener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic void forget(int netId, WifiManager.ActionListener listener)
config
- the set of variables that describe the configuration,
contained in a WifiConfiguration
object.listener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic void disable(int netId, WifiManager.ActionListener listener)
netId
- is the network Idlistener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic void disableEphemeralNetwork(String SSID)
SSID,
- in the format of WifiConfiguration's SSID.public void startWps(WpsInfo config, WifiManager.WpsCallback listener)
config
- WPS configuration (does not support WpsInfo.LABEL
)listener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic void cancelWps(WifiManager.WpsCallback listener)
listener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic Messenger getWifiServiceMessenger()
public String getConfigFile()
public WifiManager.WifiLock createWifiLock(int lockType, String tag)
lockType
- 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
- 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.WifiManager.WifiLock
public WifiManager.WifiLock createWifiLock(String tag)
tag
- 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.WifiManager.WifiLock
public WifiManager.MulticastLock createMulticastLock(String tag)
tag
- 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.WifiManager.MulticastLock
public boolean isMulticastEnabled()
public boolean initializeMulticastFiltering()
protected void finalize() throws Throwable
Object
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.
public void enableVerboseLogging(int verbose)
public int getVerboseLoggingLevel()
public void enableAggressiveHandover(int enabled)
public int getAggressiveHandover()
public void setAllowScansWithTraffic(int enabled)
public int getAllowScansWithTraffic()
public void factoryReset()
public Network getCurrentNetwork()
public boolean setEnableAutoJoinWhenAssociated(boolean enabled)
public boolean getEnableAutoJoinWhenAssociated()
public void enableWifiConnectivityManager(boolean enabled)