I'd like my android device to connect to a wifi hotspot.
I created a new wificonfiguration
and add it into the wifimanager
, this wificonfiguration
has NetworkId
.Then I invoke the function wifi.enableNetwork(NetworkId, true).
After that, I think the supplicant will go through obtaining ip address, authentication, and at last physically connect to the hotspot. So is there a way to identify if the wifi is physically connected or not?
I would prefer a handler-like method.
You can try this:
Edit: More details:
Register a
BroadcastReceiver
in your manifest like so:Then put the code above on the
onReceive()
method of your receiver like so:getNetworkInfo(int) method is deprecated. You can apply something like this
Also, please add this permission under AndroidManifest.xml
This may help you .
You can check all the network. If you only want WIFI you can remove checking other 2 network.
Don't forget to add following in manifest: