Search code examples
androidwifiandroid-wifi

How to get WIFI SSID in Android 10.0?


There's no problem getting SSID in Android 9.0&8.0
but I can't get SSID in Android 10.0(Q).
How should I do? and Where is the document links about wifi in android 10.0? I tried to find the document but I couldn't find it.

There's no problem getting SSID in Android 9.0&8.0

WifiManager mWifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
assert mWifiManager != null;
WifiInfo info = mWifiManager.getConnectionInfo();
return info.getSSID();
ConnectivityManager connManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
assert connManager != null;
NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
if (networkInfo.isConnected()) {
     if (networkInfo.getExtraInfo() != null) {
        return networkInfo.getExtraInfo().replace("\"", "");
    }
}

Solution

  • It want be get.check original post

    From android 8.0 onwards we wont be getting SSID of the connected network unless GPS is turned on.

    Get SSID when WIFI is connected

    WifiManager mWifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    assert mWifiManager != null;
    WifiInfo info = mWifiManager.getConnectionInfo();
    return info.getSSID();