I am creating an application that can use WifiManager to automatically add / connect our WiFi hosting equipment so that the user can easily get to their web interface.
Part works wifiManager.enableNetwork(i.networkId, true);. He immediately returns and after a few seconds Wi-Fi connects. But the webinterface activity starts immediately, and the pause time is WebView: the page cannot be loaded.
This is because the WiFi connection takes a few seconds. I also can not inform the user about failed connection attempts.
I read about it, and it seems to me that it BroadcastReceivercan “push out” my wifi-connect activity to start the webinterface activity. The bonus was also to visualize a failed connection.
So my questions are:
- I agree, do I need
BroadcastReceiverto WifiManager.SUPPLICANT_STATE_CHANGED_ACTIONor WifiManager.NETWORK_STATE_CHANGED_ACTION? - When to register and cancel registration?
- Can I just put a loop to check the statemachine (and timeout) between them, or will it be a bad design and why?
I hope this can be done by staying inside my application instance .. or will it essentially lead to errors when exiting the application when Wi-Fi tries to connect?
change
As for the code; I use WifiManager exactly like this: How to connect to a specific Wi-Fi network in Android software?
Android 4.1.2, /.