public class WifiManager extends Object
Context.getSystemService(Context.WIFI_SERVICE)
.
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 interface |
WifiManager.WpsListener
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 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 int |
DISABLE_NETWORK |
static int |
DISABLE_NETWORK_FAILED |
static int |
DISABLE_NETWORK_SUCCEEDED |
static int |
ENABLE_TRAFFIC_STATS_POLL |
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_CAPABILITIES
The lookup key for a
LinkCapabilities object associated with the
Wi-Fi network. |
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_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_PREVIOUS_WIFI_AP_STATE
The previous Wi-Fi state.
|
static String |
EXTRA_PREVIOUS_WIFI_STATE
The previous Wi-Fi state.
|
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_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_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 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 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 |
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 int |
TRAFFIC_STATS_POLL |
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 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_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_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)
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.
|
boolean |
addToBlacklist(String bssid)
Add a bssid to the supplicant blacklist
This API is used by WifiWatchdogService
|
static int |
calculateSignalLevel(int rssi,
int numLevels)
Calculates the level of the signal.
|
void |
cancelWps(WifiManager.ActionListener listener)
Cancel any ongoing Wi-fi Protected Setup
|
void |
captivePortalCheckComplete() |
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 |
disable(int netId,
WifiManager.ActionListener listener)
Disable network
|
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.
|
protected void |
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
void |
forget(int netId,
WifiManager.ActionListener listener)
Delete the network in the supplicant config.
|
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.
|
DhcpInfo |
getDhcpInfo()
Return the DHCP-assigned addresses from the last successful DHCP request,
if any.
|
int |
getFrequencyBand()
Get the operational frequency band.
|
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.
|
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.
|
Messenger |
getWifiStateMachineMessenger()
Get a reference to WifiStateMachine handler.
|
boolean |
initializeMulticastFiltering()
Initialize the multicast filtering to 'on'
|
boolean |
isDualBandSupported()
Check if the chipset supports dual frequency band (2.4 GHz and 5 GHz)
|
boolean |
isMulticastEnabled()
Check multicast filter status.
|
boolean |
isWifiApEnabled()
Return whether Wi-Fi AP is enabled or disabled.
|
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.
|
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 |
setCountryCode(String country,
boolean persist)
Set the country code.
|
void |
setFrequencyBand(int band,
boolean persist)
Set the operational frequency band.
|
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 |
startScan()
Request a scan for access points.
|
boolean |
startScanActive()
Request a scan for access points.
|
boolean |
startWifi()
Start the driver and connect to network.
|
void |
startWps(WpsInfo config,
WifiManager.WpsListener listener)
Start Wi-fi Protected Setup
|
boolean |
stopWifi()
Disconnect from a network (if any) and stop the driver.
|
int |
updateNetwork(WifiConfiguration config)
Update the network description of an existing configured network.
|
public static final int ERROR_AUTHENTICATING
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_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 String SUPPLICANT_CONNECTION_CHANGE_ACTION
true
means CONNECTED.public 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.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_LINK_CAPABILITIES
LinkCapabilities
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_PICK_WIFI_NETWORK
Input: Nothing.
Output: Nothing.
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 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 ENABLE_TRAFFIC_STATS_POLL
public static final int TRAFFIC_STATS_POLL
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 WifiManager(Context context, IWifiManager service)
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 when Wi-Fi is turned off, it can be null.public 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 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.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 startScan()
true
if the operation succeeded, i.e., the scan was initiatedpublic boolean startScanActive()
true
if the operation succeeded, i.e., the scan was initiatedpublic WifiInfo getConnectionInfo()
WifiInfo
.public List<ScanResult> getScanResults()
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 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 boolean setWifiApConfiguration(WifiConfiguration wifiConfig)
true
if the operation succeeded, false
otherwisepublic boolean startWifi()
true
if the operation succeeds else false
public boolean stopWifi()
true
if the operation succeeds else false
public boolean addToBlacklist(String bssid)
true
if the operation succeeds else false
public boolean clearBlacklist()
true
if the operation succeeds else false
public 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 startWps(WpsInfo config, WifiManager.WpsListener listener)
config
- WPS configurationlistener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic void cancelWps(WifiManager.ActionListener listener)
listener
- for callbacks on success or failure. Can be null.IllegalStateException
- if the WifiManager instance needs to be
initialized againpublic Messenger getWifiServiceMessenger()
public Messenger getWifiStateMachineMessenger()
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()
public void captivePortalCheckComplete()
protected void finalize() throws Throwable
Object
Note that objects that override finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.