How to get Wi-Fi hotspot clients connectivity status in android?

Viewed 856

I have created a WI-FI Hotspot in my app and then I try to show a toast message when a device connects to my hotspot.

I have tried this :

private var onClientConnected = object : BroadcastReceiver(){
    override fun onReceive(context: Context?, intent: Intent?) {
         Toast.makeText(applicationContext,"Client Connected!",Toast.LENGTH_LONG).show()
    }
}

and register it using this:

registerReceiver(onClientConnected, IntentFilter("android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED"))

But at run time when a device connects to hotspot. I get no Toast message. Is there anything that I have missed or doing wrong?

0 Answers
Related