Gurleen Sethi
Gurleen Sethi

Reputation: 3512

Getting WiFi name in Android 8.1?

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

Upvotes: 2

Views: 1199

Answers (1)

Avinash Parasurampuram
Avinash Parasurampuram

Reputation: 121

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

Upvotes: 4

Related Questions