WIFI连接实现
来源:互联网 发布:二次元狂热 淘宝 编辑:程序博客网 时间:2024/05/18 01:23
转载地址: http://blog.csdn.net/liuhui_8989/article/details/22962537
版权声明:本文为博主原创文章,未经博主允许不得转载。
目录(?)[+]
实现目标:搜索WIFI,手动输入密码并保存,连接WIFI。第二次连接该WIFI信号不需要输入密码
首先在AndroidManifest.XML中开启响应的权限
<a target=_blank id="L1" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;"> 1</a><a target=_blank id="L2" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;"> 2</a><a target=_blank id="L3" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;"> 3</a><a target=_blank id="L4" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;"> 4</a>
来自CODE的代码片wifiPermission
1、开启WIFI
<a target=_blank id="L1" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;"> 1</a><a target=_blank id="L2" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;"> 2</a><a target=_blank id="L3" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;"> 3</a><a target=_blank id="L4" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;"> 4</a><a target=_blank id="L5" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;"> 5</a><a target=_blank id="L6" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;"> 6</a>
来自CODE的代码片OpenWIFI
2、扫描WIFI信号
<a target=_blank id="L1" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;"> 1</a><a target=_blank id="L2" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;"> 2</a><a target=_blank id="L3" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;"> 3</a><a target=_blank id="L4" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;"> 4</a>
来自CODE的代码片StartScan
3、得到扫描WIFI结果
<a target=_blank id="L1" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;"> 1</a><a target=_blank id="L2" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;"> 2</a><a target=_blank id="L3" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;"> 3</a><a target=_blank id="L4" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;"> 4</a>
来自CODE的代码片getScan
4、得到WIFi的配置好的信息,包含配置好的密码
<a target=_blank id="L1" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;"> 1</a><a target=_blank id="L2" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;"> 2</a><a target=_blank id="L3" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;"> 3</a><a target=_blank id="L4" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;"> 4</a><a target=_blank id="L5" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;"> 5</a><a target=_blank id="L6" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;"> 6</a><a target=_blank id="L7" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;"> 7</a><a target=_blank id="L8" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;"> 8</a>
来自CODE的代码片getConfig
5、根据WIFI的名称SSID判定指定WIFI是否已经配置好,配置好则返回其networkId,用于连接。之前尝试了BSSID地址没成功,所以只能使用SSID
<a target=_blank id="L1" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;"> 1</a><a target=_blank id="L2" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;"> 2</a><a target=_blank id="L3" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;"> 3</a><a target=_blank id="L4" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;"> 4</a><a target=_blank id="L5" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;"> 5</a><a target=_blank id="L6" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;"> 6</a><a target=_blank id="L7" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;"> 7</a><a target=_blank id="L8" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;"> 8</a><a target=_blank id="L9" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;"> 9</a><a target=_blank id="L10" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a><a target=_blank id="L11" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a>
来自CODE的代码片IsConfiguration
6、如果需要连接的WIFI没有配置好,即没有保存密码。则为指定名称ssid的WIFI添加密码信息psw,添加成功后返回给其分配的networId,同于连接
<a target=_blank id="L1" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;"> 1</a><a target=_blank id="L2" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;"> 2</a><a target=_blank id="L3" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;"> 3</a><a target=_blank id="L4" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;"> 4</a><a target=_blank id="L5" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;"> 5</a><a target=_blank id="L6" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;"> 6</a><a target=_blank id="L7" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;"> 7</a><a target=_blank id="L8" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;"> 8</a><a target=_blank id="L9" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;"> 9</a><a target=_blank id="L10" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a><a target=_blank id="L11" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a><a target=_blank id="L12" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;"> 12</a><a target=_blank id="L13" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;"> 13</a><a target=_blank id="L14" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;"> 14</a><a target=_blank id="L15" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;"> 15</a><a target=_blank id="L16" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;"> 16</a><a target=_blank id="L17" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;"> 17</a><a target=_blank id="L18" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;"> 18</a><a target=_blank id="L19" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;"> 19</a><a target=_blank id="L20" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;"> 20</a>
来自CODE的代码片AddWifiConfig
7、根据步骤6配置好需要连接的WIFI密码信息后,下面通过networkId连接指定WIFI。在连接经过步骤6刚添加配置信息的WIFI信号之前需要重新执行下步骤4,得到新的配置好信息的列表。
<a target=_blank id="L1" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;"> 1</a><a target=_blank id="L2" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;"> 2</a><a target=_blank id="L3" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;"> 3</a><a target=_blank id="L4" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;"> 4</a><a target=_blank id="L5" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;"> 5</a><a target=_blank id="L6" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;"> 6</a><a target=_blank id="L7" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;"> 7</a><a target=_blank id="L8" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;"> 8</a><a target=_blank id="L9" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;"> 9</a><a target=_blank id="L10" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a><a target=_blank id="L11" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a><a target=_blank id="L12" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;"> 12</a><a target=_blank id="L13" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;"> 13</a><a target=_blank id="L14" href="http://blog.csdn.net/liuhui_8989/article/details/22962537#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;"> 14</a>
来自CODE的代码片ConnectWifi
这只是简单的应用。
project源码:http://download.csdn.net/detail/liuhui_8989/7154671
有错误多多指出
0 0
- 实现自动WiFi连接
- WIFI连接实现
- 实现无线wifi连接
- Android代码实现WiFi连接
- Android编程实现连接Wifi(运用Wifi 相关 API)
- Android编程实现连接Wifi(运用Wifi 相关 API)
- Android编程实现连接Wifi(运用Wifi 相关 API)
- Android编程实现连接Wifi(运用Wifi 相关 API)
- 如何设置无线路由器实现wifi连接
- Android 实现WiFi列表显示与连接
- android4.0 WIFI实现网络连接
- 利用Wifidog实现微信wifi连接
- Android 简单的实现WIFI连接
- wifi连接
- WIFI连接
- android实现打开wifi选项,并等待在连接成功后返回连接的wifi信息
- 基于wpa_supplicant库的WIFI连接功能实现--wifi扫描功能实现
- 通过WifiManager可以实现对wifi进行操作,实现wifi自动连接等一些功能
- 内存溢出的一些个学习整理
- Oracle 常用系统包(转)
- UITableView 总结
- linux yum命令详解
- Cookie/Session机制详解
- WIFI连接实现
- JS积累
- Oracle9I新增语法 merge into
- Quartz定时调度CronTrigger时间配置格式说明与实例
- iOS 多线程 performSelector 与 NSInvocation的使用——iOS 编码复习(三)(多线程1)
- postgres配置主从流复制
- NIO与传统IO的区别
- DEV 控件使用技巧
- 变不可能为可能,Tachyon帮助Spark变小时级任务到秒