How to get WIFI SSID in Android 9.0(PIE)? My code is working fine till android version 8.1.0 but it is not working on Android 9.0
ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
wifiInfo.getSSID();
String name = networkInfo.getExtraInfo();
String ssid = "\"" + wifiInfo.getSSID() + "\"";
}
But this code is not working on Android 9.0
You can access to the ssid wifi that you are connnected to it in Android 8 with location permission, but in android 9 you have to turn on location. read more here: https://developer.android.com/about/versions/pie/android-9.0-changes-all