博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WifiManager类具体解释
阅读量:7073 次
发布时间:2019-06-28

本文共 16530 字,大约阅读时间需要 55 分钟。

public class

WifiManager

extends 
   ↳ android.net.wifi.WifiManager

类概述

This class provides the primary API for managing all aspects of Wi-Fi connectivity. Get an instance of this class by calling . It deals with several categories of items:

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

摘要

嵌套类
class Allows an application to receive Wifi Multicast packets. 
class Allows an application to keep the Wi-Fi radio awake. 
常量
Activity Action: Pick a Wi-Fi network to connect to.
int The error code if there was a problem authenticating.
The lookup key for a String giving the BSSID of the access point to which we are connected.
The lookup key for a  object associated with the Wi-Fi network.
The lookup key for an int giving the new RSSI in dBm.
The lookup key for a  describing the new state Retrieve with .
The previous Wi-Fi state.
The lookup key for a boolean that indicates whether a connection to the supplicant daemon has been gained or lost.
The lookup key for a  describing the supplicant error code if any Retrieve with .
The lookup key for an int that indicates whether Wi-Fi is enabled, disabled, enabling, disabling, or unknown.
The network IDs of the configured networks could have changed.
Broadcast intent action indicating that the state of Wi-Fi connectivity has changed.
The RSSI (signal strength) has changed.
An access point scan has completed, and results are available from the supplicant.
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.
Broadcast intent action indicating that the state of establishing a connection to an access point has changed.One extra provides the new .
int In this Wi-Fi lock mode, Wi-Fi will be kept active, and will behave normally, i.e., it will attempt to automatically establish a connection to a remembered access point that is within range, and will do periodic scans if there are remembered access points but none are in range.
int 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.
Broadcast intent action indicating that Wi-Fi has been enabled, disabled, enabling, disabling, or unknown.
int Wi-Fi is disabled.
int Wi-Fi is currently being disabled.
int Wi-Fi is enabled.
int Wi-Fi is currently being enabled.
int Wi-Fi is in an unknown state.
公有方法
int ( config)
Add a new network description to the set of configured networks.
static int (int rssi, int numLevels)
Calculates the level of the signal.
static int (int rssiA, int rssiB)
Compares two signal strengths.
( tag)
Create a new MulticastLock
(int lockType,  tag)
Creates a new WifiLock.
( tag)
Creates a new WifiLock.
boolean (int netId)
Disable a configured network.
boolean ()
Disassociate from the currently active access point.
boolean (int netId, boolean disableOthers)
Allow a previously configured network to be associated with.
<> ()
Return a list of all the networks configured in the supplicant.
()
Return dynamic information about the current Wi-Fi connection, if any is active.
()
Return the DHCP-assigned addresses from the last successful DHCP request, if any.
<> ()
Return the results of the latest access point scan.
int ()
Gets the Wi-Fi enabled state.
boolean ()
Return whether Wi-Fi is enabled or disabled.
boolean ()
Check that the supplicant daemon is responding to requests.
boolean ()
Reconnect to the currently active access point, even if we are already connected.
boolean ()
Reconnect to the currently active access point, if we are currently disconnected.
boolean (int netId)
Remove the specified network from the list of configured networks.
boolean ()
Tell the supplicant to persist the current list of configured networks.
boolean (boolean enabled)
Enable or disable Wi-Fi.
boolean ()
Request a scan for access points.
int ( config)
Update the network description of an existing configured network.
继承的方法
 来自 class 

常量

public static final  ACTION_PICK_WIFI_NETWORK

引入自:

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

Input: Nothing.

Output: Nothing.

常量值: "android.net.wifi.PICK_WIFI_NETWORK"

public static final int ERROR_AUTHENTICATING

引入自:

The error code if there was a problem authenticating.

常量值: 1 (0x00000001)

public static final  EXTRA_BSSID

引入自:

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

常量值: "bssid"

public static final  EXTRA_NETWORK_INFO

引入自:

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

常量值: "networkInfo"

public static final  EXTRA_NEW_RSSI

引入自:

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

常量值: "newRssi"

public static final  EXTRA_NEW_STATE

引入自:

The lookup key for a  describing the new state Retrieve with .

常量值: "newState"

public static final  EXTRA_PREVIOUS_WIFI_STATE

引入自:

The previous Wi-Fi state.

參见
常量值: "previous_wifi_state"

public static final  EXTRA_SUPPLICANT_CONNECTED

引入自:

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

常量值: "connected"

public static final  EXTRA_SUPPLICANT_ERROR

引入自:

The lookup key for a  describing the supplicant error code if any Retrieve with .

參见
常量值: "supplicantError"

public static final  EXTRA_WIFI_STATE

引入自:

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

參见
常量值: "wifi_state"

public static final  NETWORK_IDS_CHANGED_ACTION

引入自:

The network IDs of the configured networks could have changed.

常量值: "android.net.wifi.NETWORK_IDS_CHANGED"

public static final  NETWORK_STATE_CHANGED_ACTION

引入自:

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

參见
常量值: "android.net.wifi.STATE_CHANGE"

public static final  RSSI_CHANGED_ACTION

引入自:

The RSSI (signal strength) has changed.

參见
常量值: "android.net.wifi.RSSI_CHANGED"

public static final  SCAN_RESULTS_AVAILABLE_ACTION

引入自:

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

常量值: "android.net.wifi.SCAN_RESULTS"

public static final  SUPPLICANT_CONNECTION_CHANGE_ACTION

引入自:

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

參见
常量值: "android.net.wifi.supplicant.CONNECTION_CHANGE"

public static final  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 . 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.

參见
常量值: "android.net.wifi.supplicant.STATE_CHANGE"

public static final 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.

常量值: 1 (0x00000001)

public static final int WIFI_MODE_SCAN_ONLY

引入自:

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

常量值: 2 (0x00000002)

public static final  WIFI_STATE_CHANGED_ACTION

引入自:

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

參见
常量值: "android.net.wifi.WIFI_STATE_CHANGED"

public static final int WIFI_STATE_DISABLED

引入自:

Wi-Fi is disabled.

參见
常量值: 1 (0x00000001)

public static final int WIFI_STATE_DISABLING

引入自:

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

參见
常量值: 0 (0x00000000)

public static final int WIFI_STATE_ENABLED

引入自:

Wi-Fi is enabled.

參见
常量值: 3 (0x00000003)

public static final int WIFI_STATE_ENABLING

引入自:

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

參见
常量值: 2 (0x00000002)

public static final int WIFI_STATE_UNKNOWN

引入自:

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

參见
常量值: 4 (0x00000004)

公有方法

public int addNetwork ( config)

引入自:

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

The new network will be marked DISABLED by default. To enable it, called .

參数
config the set of variables that describe the configuration, contained in a  object.
返回值
  • the ID of the newly created network description. This is used in other operations to specified the network to be acted upon. Returns -1 on failure.

public static int calculateSignalLevel (int rssi, int numLevels)

引入自:

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

參数
rssi The power of the signal measured in RSSI.
numLevels The number of levels to consider in the calculated level.
返回值
  • A level of the signal, given in the range of 0 to numLevels-1 (both inclusive).

public static int compareSignalLevel (int rssiA, int rssiB)

引入自:

Compares two signal strengths.

參数
rssiA The power of the first signal measured in RSSI.
rssiB The power of the second signal measured in RSSI.
返回值
  • Returns <0 if the first signal is weaker than the second signal, 0 if the two signals have the same strength, and >0 if the first signal is stronger than the second signal.

public  createMulticastLock ( tag)

引入自:

Create a new MulticastLock

參数
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.
返回值
  • a new, unacquired MulticastLock with the given tag.
參见

public  createWifiLock (int lockType,  tag)

引入自:

Creates a new WifiLock.

參数
lockType the type of lock to create. See , and  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.
返回值
  • a new, unacquired WifiLock with the given tag.
參见

public  createWifiLock ( tag)

引入自:

Creates a new WifiLock.

參数
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.
返回值
  • a new, unacquired WifiLock with the given tag.
參见

public boolean disableNetwork (int netId)

引入自:

Disable a configured network. The specified network will not be a candidate for associating. This may result in the asynchronous delivery of state change events.

參数
netId the ID of the network as returned by .
返回值
  • true if the operation succeeded

public boolean disconnect ()

引入自:

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

返回值
  • true if the operation succeeded

public boolean enableNetwork (int netId, boolean disableOthers)

引入自:

Allow a previously configured network to be associated with. If disableOthers is true, then all other configured networks are disabled, and an attempt to connect to the selected network is initiated. This may result in the asynchronous delivery of state change events.

參数
netId the ID of the network in the list of configured networks
disableOthers 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 succeeded

public <> getConfiguredNetworks ()

引入自:

Return a list of all the networks configured in the supplicant. Not all fields of WifiConfiguration are returned. Only the following fields are filled in:

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

返回值
  • a list of network configurations in the form of a list of  objects.

public  getConnectionInfo ()

引入自:

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

返回值
  • the Wi-Fi information, contained in .

public  getDhcpInfo ()

引入自:

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

返回值
  • the DHCP information

public <> getScanResults ()

引入自:

Return the results of the latest access point scan.

返回值
  • the list of access points found in the most recent scan.

public int getWifiState ()

引入自:

Gets the Wi-Fi enabled state.

返回值
  • One of 
參见

public boolean isWifiEnabled ()

引入自:

Return whether Wi-Fi is enabled or disabled.

返回值
  • true if Wi-Fi is enabled
參见

public boolean pingSupplicant ()

引入自:

Check that the supplicant daemon is responding to requests.

返回值
  • true if we were able to communicate with the supplicant and it returned the expected response to the PING message.

public boolean reassociate ()

引入自:

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

返回值
  • true if the operation succeeded

public boolean reconnect ()

引入自:

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

返回值
  • true if the operation succeeded

public boolean removeNetwork (int netId)

引入自:

Remove the specified network from the list of configured networks. This may result in the asynchronous delivery of state change events.

參数
netId the integer that identifies the network configuration to the supplicant
返回值
  • true if the operation succeeded

public boolean saveConfiguration ()

引入自:

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

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

返回值
  • true if the operation succeeded

public boolean setWifiEnabled (boolean enabled)

引入自:

Enable or disable Wi-Fi.

參数
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 boolean startScan ()

引入自:

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

返回值
  • true if the operation succeeded, i.e., the scan was initiated

public int updateNetwork ( config)

引入自:

Update the network description of an existing configured network.

參数
config the set of variables that describe the configuration, contained in a  object. It may be sparse, so that only the items that are being changed are non-null. The networkId field must be set to the ID of the existing network being updated.
返回值
  • Returns the networkId of the supplied WifiConfiguration on success. 
    Returns -1 on failure, including when the networkId field of the WifiConfiguration does not refer to an existing network.

转载地址:http://wzkml.baihongyu.com/

你可能感兴趣的文章
cp命令覆盖文件时不用按Y来确认的方法
查看>>
Tomcat优化
查看>>
【开源专访】Sea.js创始人玉伯的前端开发之路
查看>>
前台实现下载xml功能
查看>>
运营商 WLAN
查看>>
并发编程 —— ScheduledThreadPoolExecutor
查看>>
Octopus系列之各个页面调用示例
查看>>
zabbix 监控域名证书到期时间!!!!
查看>>
Java Magic. Part 1: java.net.URL
查看>>
异步实现服务器推送消息(聊天功能示例)
查看>>
Python中一个经典的参数错误
查看>>
AutoResetEvent详解
查看>>
Lumen框架—升级改造之路-开篇
查看>>
vs2013 sn key
查看>>
轻松记账工程冲刺第四天
查看>>
pig安装
查看>>
《R实战》读书笔记一
查看>>
Caused by: java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery
查看>>
惊魂时刻!技术生涯中遇到的最让你担惊受怕的事件是什么?
查看>>
JavaScript中两个感叹号的作用
查看>>