8

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("\"", "");
    }
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
a2633063
  • 83
  • 1
  • 3

1 Answers1

9

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();
Déborah
  • 5
  • 2
Chanaka Weerasinghe
  • 5,404
  • 2
  • 26
  • 39
  • it does not work with Android 10 (Q). The wifi name of OS is still showing event without GPS – T D Nguyen Jun 27 '23 at 03:08
  • This did not work at first but then I requested permissions from the user before calling this and it finally worked. I don't recall which particular permission made this finally work though. – Randy Burden Jul 13 '23 at 18:25