|
Android 2.3 Gingerbread | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.net.wifi.WifiManager
public class 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:
ConnectivityManager.
| Nested Class Summary | |
|---|---|
class |
WifiManager.MulticastLock
Allows an application to receive Wifi Multicast packets. |
class |
WifiManager.WifiLock
Allows an application to keep the Wi-Fi radio awake. |
| Field Summary | |
|---|---|
static String |
ACTION_PICK_WIFI_NETWORK
Activity Action: Pick a Wi-Fi network to connect to. |
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_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_STATE
The lookup key for an int that indicates whether Wi-Fi is enabled, disabled, enabling, disabling, or unknown. |
(package private) Handler |
mHandler
|
(package private) android.net.wifi.IWifiManager |
mService
|
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 String |
SCAN_RESULTS_AVAILABLE_ACTION
An access point scan has completed, and results are available from the supplicant. |
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 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 behave as in the mode WIFI_MODE_FULL but it operates at high performance
at the expense of power. |
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. |
| Constructor Summary | |
|---|---|
WifiManager(android.net.wifi.IWifiManager service,
Handler handler)
Create a new WifiManager instance. |
|
| Method Summary | |
|---|---|
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. |
static int |
compareSignalLevel(int rssiA,
int rssiB)
Compares two signal strengths. |
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. |
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. |
int |
getNumAllowedChannels()
Return the number of frequency channels that are allowed to be used in the current regulatory domain. |
List<ScanResult> |
getScanResults()
Return the results of the latest access point scan. |
int[] |
getValidChannelCounts()
Return the list of valid values for the number of allowed radio channels for various regulatory domains. |
WifiConfiguration |
getWifiApConfiguration()
Gets the Wi-Fi AP Configuration. |
int |
getWifiApState()
Gets the Wi-Fi enabled state. |
int |
getWifiState()
Gets the Wi-Fi enabled state. |
boolean |
initializeMulticastFiltering()
Initialize the multicast filtering to 'on' |
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. |
boolean |
saveConfiguration()
Tell the supplicant to persist the current list of configured networks. |
boolean |
setNumAllowedChannels(int numChannels,
boolean persist)
Set the number of frequency channels that are allowed to be used in the current regulatory domain. |
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. |
int |
updateNetwork(WifiConfiguration config)
Update the network description of an existing configured network. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int ERROR_AUTHENTICATING
public static final String WIFI_STATE_CHANGED_ACTION
EXTRA_WIFI_STATE,
EXTRA_PREVIOUS_WIFI_STATE,
Constant Field Valuespublic static final String EXTRA_WIFI_STATE
Intent.getIntExtra(String,int).
WIFI_STATE_DISABLED,
WIFI_STATE_DISABLING,
WIFI_STATE_ENABLED,
WIFI_STATE_ENABLING,
WIFI_STATE_UNKNOWN,
Constant Field Valuespublic 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.
WIFI_STATE_CHANGED_ACTION,
getWifiState(),
Constant Field Valuespublic static final int WIFI_STATE_DISABLED
WIFI_STATE_CHANGED_ACTION,
getWifiState(),
Constant Field Valuespublic static final int WIFI_STATE_ENABLING
WIFI_STATE_ENABLED if
it finishes successfully.
WIFI_STATE_CHANGED_ACTION,
getWifiState(),
Constant Field Valuespublic static final int WIFI_STATE_ENABLED
WIFI_STATE_CHANGED_ACTION,
getWifiState(),
Constant Field Valuespublic static final int WIFI_STATE_UNKNOWN
WIFI_STATE_CHANGED_ACTION,
getWifiState(),
Constant Field Valuespublic static final String WIFI_AP_STATE_CHANGED_ACTION
public static final String EXTRA_WIFI_AP_STATE
Intent.getIntExtra(String,int).
WIFI_AP_STATE_DISABLED,
WIFI_AP_STATE_DISABLING,
WIFI_AP_STATE_ENABLED,
WIFI_AP_STATE_ENABLING,
WIFI_AP_STATE_FAILED,
Constant Field Valuespublic 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.
WIFI_AP_STATE_CHANGED_ACTION,
getWifiApState(),
Constant Field Valuespublic static final int WIFI_AP_STATE_DISABLED
WIFI_AP_STATE_CHANGED_ACTION,
getWifiState(),
Constant Field Valuespublic static final int WIFI_AP_STATE_ENABLING
WIFI_AP_STATE_ENABLED if it finishes successfully.
WIFI_AP_STATE_CHANGED_ACTION,
getWifiApState(),
Constant Field Valuespublic static final int WIFI_AP_STATE_ENABLED
WIFI_AP_STATE_CHANGED_ACTION,
getWifiApState(),
Constant Field Valuespublic static final int WIFI_AP_STATE_FAILED
WIFI_AP_STATE_CHANGED_ACTION,
getWifiApState(),
Constant Field Valuespublic 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, a second extra may provide the BSSID of the access point,
as a String.
EXTRA_NETWORK_INFO,
EXTRA_BSSID,
Constant Field Valuespublic 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 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.
EXTRA_NEW_STATE,
EXTRA_SUPPLICANT_ERROR,
Constant Field Valuespublic 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 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 NETWORK_IDS_CHANGED_ACTION
public static final String ACTION_PICK_WIFI_NETWORK
Input: Nothing.
Output: Nothing.
public static final int WIFI_MODE_FULL_HIGH_PERF
WIFI_MODE_FULL but it operates at high performance
at the expense of power. This mode should be used
only when the wifi connection needs to have minimum loss and low
latency as it can impact the battery life.
public static final int WIFI_MODE_FULL
public static final int WIFI_MODE_SCAN_ONLY
android.net.wifi.IWifiManager mService
Handler mHandler
| Constructor Detail |
|---|
public WifiManager(android.net.wifi.IWifiManager service,
Handler handler)
Context.getSystemService() to retrieve
the standard Context.WIFI_SERVICE.
service - the Binder interfacehandler - target for messages| Method Detail |
|---|
public List<WifiConfiguration> getConfiguredNetworks()
WifiConfiguration objects.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 supplicant
true if the operation succeeded
public 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 int getNumAllowedChannels()
-1 if an error occurs
public boolean setNumAllowedChannels(int numChannels,
boolean persist)
numChannels - the number of allowed channels. Must be greater than 0
and less than or equal to 16.persist - true if you want this remembered
true if the operation succeeds, false otherwise, e.g.,
numChannels is out of range.public int[] getValidChannelCounts()
null if the operation failspublic 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_UNKNOWNisWifiEnabled()public boolean isWifiEnabled()
true if Wi-Fi is enabledgetWifiState()
public 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 WifiConfiguration
true 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_FAILEDisWifiApEnabled()public boolean isWifiApEnabled()
true if Wi-Fi AP is enabledgetWifiApState()public WifiConfiguration getWifiApConfiguration()
public boolean setWifiApConfiguration(WifiConfiguration wifiConfig)
true if the operation succeeded, false otherwise
public WifiManager.WifiLock createWifiLock(int lockType,
String tag)
lockType - the type of lock to create. See WIFI_MODE_FULL,
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.WifiLockpublic 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.WifiLockpublic 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.MulticastLockpublic boolean isMulticastEnabled()
public boolean initializeMulticastFiltering()
|
Android 2.3 Gingerbread | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||