On Oreo (8.1.0) not getting the correct Wifi SSID. It's showing though it is connected to a wifi with SSID

前端 未结 7 1062
名媛妹妹
名媛妹妹 2021-01-02 03:02

I need to check the current connected wifi SSID on android. I checked with Nokia 6 and OnePlus 5 with respectively Oreo 8.1.0 and Oreo 8.0. Other phones with different OS v

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 03:24

    In Android Oreo you could use ConnectivityManager to know your wifi SSID.

    Permission

    
    

    Code to get SSID

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null && info.isConnected()) {
        String ssid = info.getExtraInfo();
        Log.d(TAG, "WiFi SSID: " + ssid);
    }
    

    This is tested in Android Oreo 8.1.0. You will get SSID enclosed with double quotes.

提交回复
热议问题