Android如何获取Wifi名称即SSID

可以使用WifiManager和WifiInfo来获取当前Wifi连接信息

[java]  view plain copy
  1. WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);  
  2. WifiInfo wifiInfo = wifiManager.getConnectionInfo();  
  3. Log.d("wifiInfo", wifiInfo.toString());  
  4. Log.d("SSID",wifiInfo.getSSID());  

记得在Manifest文件中添加许可

<code><span class="pun"><</span><span class="pln">uses</span><span class="pun">-</span><span class="pln">permission android</span><span class="pun">:</span><span class="pln">name</span><span class="pun">=</span><span class="str">"android.permission.ACCESS_WIFI_STATE"</span><span class="pun">></span><span class="pln"></span><span class="pun"></</span><span class="pln">uses</span><span class="pun">-</span><span class="pln">permission</span><span class="pun">></span></code>

如果不是想获取当前连接,而是想获取WIFI设置中的连接

可以使用

[java]  view plain copy
  1. WifiManager.getConfiguredNetworks()  

参考链接:

http://developer.android.com/reference/android/net/wifi/WifiInfo.html#getSSID%28%29

http://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks%28%29


你可能感兴趣的:(Android如何获取Wifi名称即SSID)