Part of my application function is to scan and display a list of Wi-Fi access points, and then connect to the one selected by the user. I have this functionality. Now I also want to be notified when the connection "passes." It should be pretty simple, but I find myself stumbling.
I read various posts here at SO and they all mention registration for WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION or WifiManager.WIFI_STATE_CHANGED_ACTION . However, none of them work for me. Can anyone spot an error in this code? (I leave the details that perform the scan and so on)
Expected behavior: As soon as the connection is successful (that is, when I see the βconnectedβ icon in the notification panel), the broadcast should be received, and I should see a toast.
Observed behavior: Broadcasting is received the first time the application is launched and whenever I return to it (i.e. when onResume() is onResume() or I suspect whenever I register for the intent)
public class WifiScanActivity extends Activity { WifiManager mainWifi; WifiReceiver mWifiReceiver; IntentFilter mIntentFilter; private final static String TAG = "WifiScanActivity"; public static final String INTENT_FOR_WIFI_CONNECTED = WifiManager.WIFI_STATE_CHANGED_ACTION;
If I uncomment the code for WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION, I donβt see the broadcast being received at all.
Note I know that the connection was successful because I see the status on the Android Wi-Fi settings screen.
source share