How to get Wifi SSID in API 26 >=

51 Views Asked by At

I'm asking about the the best method for obtaining the SSID of the presently connected WiFi network, particularly for Android API versions 26 through 34 ?

We use the Wifimanger getConnectionInfo() method to obtain the SSID and BBSID of the connected wifi. However, starting with Android API version 31, the getConnectionInfo() method has been deprecated.

i also have used connectivity manager , with network callback

val request = NetworkRequest.Builder()
            .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
            .build()
        val networkCallback = object : ConnectivityManager.NetworkCallback(
            FLAG_INCLUDE_LOCATION_INFO) {
            override fun onCapabilitiesChanged(
                network: Network,
                networkCapabilities: NetworkCapabilities
            ) {
                super.onCapabilitiesChanged(network, networkCapabilities)
                val wifiInfo = networkCapabilities.transportInfo as WifiInfo
                val ssid = wifiInfo.ssid
            }
        }
        connManager.registerNetworkCallback(request, networkCallback)

but it will fetch multiple ssid (sometimes it unknown)

0

There are 0 best solutions below