What you're looking for is call broadcast receiver. basically, you create a custom broadcast receiver that will receive message on some actions. you define those action in an intent filter :
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
then register your receiver on this intent filter :
registerReceiver(wifiWatcher, intentFilter);
and your receiver will implement the onReceive method :
public void onReceive( Context context, Intent intent )
ConnectivityManager conMngr = (ConnectivityManager)this.getSystemService(this.CONNECTIVITY_SERVICE);
android.net.NetworkInfo wifi = conMngr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
String ssid = null;
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo != null && !StringUtil.isBlank(connectionInfo.getSSID())) {
ssid = connectionInfo.getSSID();
}
}
Well, do what you want if the correct SSID
if (ssid!=null && ssid.equals(mySSID){
//DO
}
to do that, you need to add those permissions in your manifest :
<user-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<user-permission android:name="android.permission.ACCESS_WIFI_STATE" />