WifiManager、ScanResult(一)

转载请标明出处:http://blog.csdn.net/xx326664162/article/details/49385761 文章出自:薛瑄的博客

你也可以查看我的其他同类文章,也会让你有一定的收货!

关于Android WiFi,我写了5篇文章,讲解了在配置WiFi中用到的知识

WifiManager、ScanResult(一)
WifiInfo(二)
ConnectivityManager(三)
NetworkInfo和NetworkInfo.State(四)
WifiManager、WifiInfo、WifiConfiguration集成类(五)

类 WifiManager

该类主要用于操作、判断、获取WiFi连接的信息,以下是常用的函数

(WifiManager) context.getSystemService(Context.WIFI_SERVICE)
获得WifiManager的对象


boolean isWifiEnabled()
判断无线网络是否开启

boolean setWifiEnabled(boolean enabled)
关闭或开启无线网络


boolean startScan()
Request a scan for access points.

List< ScanResult > getScanResults()
Return the results of the latest access point scan.

一般先使用startScan()扫描周围WiFi,再使用getScanResults()获得WiFi列表里的热点信息。


List< WifiConfiguration > getConfiguredNetworks()
Return a list of all the networks configured in the supplicant.

  • 该函数返回的结果是曾经连接成功过的WiFi,如果手机已经root过,查看连接过 的wifi在RE管理器中路径:data/misc/wifi/wpa_supplicant.conf。
  • 如果想要连接的网络不再这个列表中,说明未连接过,可以创建一个WifiConfiguration对象,并使用addNetwork添加新网络
  • WifiConfiguration示例代码

int addNetwork(WifiConfiguration config)
Add a new network description to the set of configured networks.
参数config的配置,请参见 WifiConfiguration示例代码

boolean enableNetwork(int netId, boolean disableOthers)
Allow a previously configured network to be associated with.
连接到addNetwork()添加的网络,这两个方法联合使用,连接到指定的一个网络上


WifiInfo getConnectionInfo()
Return dynamic information about the current Wi-Fi connection, if any is active. 获取当前连接的WiFi信息

boolean removeNetwork(int netId)
Remove the specified network from the list of configured networks.
移除一个指定的网络从网络配置列表中

DhcpInfo getDhcpInfo()
Return the DHCP-assigned addresses from the last successful DHCP request, if any.

ScanResult

成员变量

public StringBSSIDThe address of the access point.
public StringSSIDThe network name.
public StringcapabilitiesDescribes the authentication, key management, and encryption schemes supported by the access point.
public intfrequencyThe frequency in MHz of the channel over which the client is communicating with the access point.
public intlevelThe detected signal level in dBm, also known as the RSSI.
public longtimestamptimestamp in microseconds (since boot) when this result was last seen.

关注我的公众号,轻松了解和学习更多技术
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛瑄

文章不错,请博主吃包辣条

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值