I need to check the current connected wifi SSID on android. I checked with Nokia 6 and OnePlus 5 with respectively Oreo 8.1.0 and Oreo 8.0. Other phones with different OS version is working fine with this code. Is there anything wrong with my code?private WifiInfo wifiInfo;private String ssid = "";private WifiManager wifiManager;private boolean getWifiStatus() { wifiManager= (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiInfo = wifiManager.getConnectionInfo(); ssid = ""; ssid = wifiInfo.getSSID(); ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isWiFi = false; if(activeNetwork != null){ isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI; } Log.d(TAG, "getWifiStatus: " + ssid); if(ssid.contains("TripleMZim") && wifiManager.isWifiEnabled() && isWiFi ){ return true; } else{ return false; }}permission in Manifest file:<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.INTERNET"/> 解决方案 Oreo 8.1+ devices require the coarse location runtime permission as well as location services to be turned on before being able to retrieve the connected SSID as it can infer the users location.Further information is available hereWhich relates to this 这篇关于在奥利奥(8.1.0)上,未获得正确的Wifi SSID.显示&lt; unknown ssid&gt;虽然它已连接到具有SSID的wifi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 20:59