Im developing an android app. For this app to work the Wi-Fi needs to be enabled all the time. Because the Wi-Fi is enabled it will keep on scanning for available networks.
I want some function to be called as soon as the Wi-Fi connects to a particular network. How do I achieve this?
I have written the following code but this works only once, how do I make this scan for networks continuously?
ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(wifi.isConnected()){
final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo != null && !(connectionInfo.getSSID().equals(""))) {
String ssid = connectionInfo.getSSID();
}
Log.i("wifi", "connected");
}
else{
Log.i("wifi", "not connected");
}