2

I want to get the name of connected WiFi in Android 8.1. When I get the SSID it returns "unknown ssid". Some answers on Stack-overflow say to get Location permissions. I even did that, but the issue persists.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return getString(R.string.grant_location_permission_wifi_name)
        }
    }
    val wifiInfo = mWifiManager.connectionInfo
    return wifiInfo.ssid
Gurleen Sethi
  • 3,162
  • 6
  • 26
  • 48

1 Answers1

4

Make sure your GPS is also switched on. It doesn't work if the GPS is off.