如何在 Android 9.0(PIE) 中获取 WIFI SSID?我的代码在 android 版本 8.1.0 之前工作正常,但在 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() + "\"";
}
但此代码不适用于 Android 9.0