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

前端 未结 7 1016
名媛妹妹
名媛妹妹 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

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    

    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.

    0 讨论(0)
提交回复
热议问题