I want to send data over local network using wifi. Before sending data I check the wifi state, and, if it not enabled, ask the user and turn wifi on. The problem is if I turn wifi on and try to use it immediately, I have got an error cause the wifi need some time to be turned on.
So, as I think, I need to turn wifi on and set the handler which will be called when wifi goes to enabled state. But WifiManager doesn't provide such methods with handlers. How I can catch changing of wifi state?
UPD
How I turn wifi on:
WifiManager wifi = WifiUtils.getWifi( getApplicationContext() );
if (WifiUtils.isWifiEnabled( wifi)) return true;
wifi.setWifiEnabled(true);
//---
public static WifiManager getWifi( Context ctx)
{
return (WifiManager)ctx.getSystemService(ctx.WIFI_SERVICE);
}
public static boolean isWifiEnabled( WifiManager wifi)
{
if (wifi==null) return false;
if (wifi.getWifiState()!=wifi.WIFI_STATE_ENABLED) return false;
return true;
}