首先AndroidMainfest.xml文件里加入权限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 获取WIFI信息状态的权限 --> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 获取网络状态改变的权限 -->然后再activity中加入例如以下代码:
private String getConnectWifiSsid(){ WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); Log.d("wifiInfo", wifiInfo.toString()); Log.d("SSID",wifiInfo.getSSID()); return wifiInfo.getSSID(); }
该接口即返回当前连接的wifi的名字。也就是SSID。 标签:Log,wifiInfo,wifi,wifiManager,Android,连接,SSID From: https://www.cnblogs.com/wanglongjiang/p/17463569.html