How to get the SSID of the Wi-Fi hotspot from the receiver to receive changes in the request state

I have a register for the broadcast receiver SUPPLICANT_STATE_CHANGED_ACTION

where I watch the state change of the wifi supplicant.

When the wifi connection state is connected or disconnected, I want to display a Toast message to the user saying you are connected / disconnected from this SSID.

I do not know from the broadcast receiver SUPPLICANT_STATE_CHANGED_ACTION

how we can get the SSID for which these events occurred, or the transmission was received.



source to share

2 answers

Try using WifiManager to get SSID.

WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String ssid = wm.getConnectionInfo().getSSID();


Also you need to save the SSID in your settings in order to display it when you receive a "disconnect" broadcast. Storing the SSID in a variable would be unsafe because it can be garbage collected at any time.




Broadcast action indicating that the Wi-Fi connection status has changed. One additional parameter provides the new state as a NetworkInfo object. If the new state is connected, additional options can provide the BSSID and WifiInfo of the access point. as a string.



All Articles