Description
I am unable to get WIFI SSID using the onCapabilitiesChanged
in the ConnectivityManager.NetworkCallback
class in Android-12.
In Android-12, getConnectionInfo is deprecated. So, as the android document suggests I am trying to get the WifiInfo
object using onCapabilitiesChanged
.
Like this,
@Override
public void onCapabilitiesChanged(@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) {
super.onCapabilitiesChanged(network, networkCapabilities);
WifiInfo wifiInfo = (WifiInfo) networkCapabilities.getTransportInfo();
}
But, when I print the WifiInfo
object. it will print SSID: <unknown ssid> and getHiddenSSID
return true.
Unexpected behavior is,
Android-12 device is connected with one WIFI (Ex. ABC)
- When I try to get WIFI SSID using
getConnectionInfo
. it return SSID: ABC and getHiddenSSID : false - But, for the same network when I try to get WIFI SSID using
onCapabilitiesChanged
, it returns SSID: <unknown ssid> and getHiddenSSID : true
Note: Location permission is provided.