0

I try to get an intent action in my receiver just after the actual connection with a wireless network has been established.

I'm now working with "NETWORK_STATE_CHANGED_ACTION" but this is fired when the connection has been successful but not yet activated. It takes a few seconds to fully connect and that's when isConnected() returns true (which I use to mark some changes).

ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo wifiNI = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

wifiNI.isConnected();

I also tried using "SUPPLICANT_CONNECTION_CHANGE_ACTION" but I couldn't get any action in my receiver.

Any ideas?

EDIT:

Eventually, the solution was in "NETWORK_STATE_CHANGED_ACTION" where I should have paid attention to NetworkInfo state:

    NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    NetworkInfo.State state = networkInfo.getState();

    if(state.equals(NetworkInfo.State.CONNECTED))
    { 
        // wireless is now connected 
    }
  • http://stackoverflow.com/questions/5888502/how-to-detect-when-wifi-connection-has-been-established-in-android?rq=1 – Snehal Poyrekar Jul 17 '14 at 11:32
  • As I have already mentioned, "SUPPLICANT_CONNECTION_CHANGE_ACTION" does not work for me. Same as this user here: https://stackoverflow.com/questions/5888502/how-to-detect-when-wifi-connection-has-been-established-in-android?rq=1#comment26991696_5890553 – klitemnistra Jul 17 '14 at 12:02

1 Answers1

0

Register your receiver with the following

        wifiReceiver = new WifiReceiver();

        final IntentFilter newFilter = new IntentFilter();
        newFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
        newFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
        newFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
        newFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
        newFilter.addAction(WifiManager.EXTRA_SUPPLICANT_CONNECTED);

        registerReceiver(wifiReceiver, newFilter);

You would have to see at least one of these actions.

axl coder
  • 739
  • 3
  • 19
  • SCAN_RESULTS does not inform about wireless connections, WIFI_STATE is about the wireless state (ON/OFF), the SUPPLICANT ones are not working for me (I mentioned it above as I also did about NETWORK_STATE). Does this code worked for you on the issue I describe in my question? – klitemnistra Jul 18 '14 at 08:30
  • I post the solution that worked for me, you don't receive nothing whit this register? – axl coder Jul 18 '14 at 09:14
  • I do receive actions but nothing that solves my issue. I'm looking for an intent that notifies the receiver when the actual connection has been fully established, not just the successful set of a new network (for which NETWORK_STATE works good). – klitemnistra Jul 18 '14 at 10:06
  • Take a look at the answer of usman here and let me know: http://stackoverflow.com/questions/5888502/how-to-detect-when-wifi-connection-has-been-established-in-android – axl coder Jul 18 '14 at 10:20
  • Fortunately, it was right there in NETWORK_STATE_CHANGED_ACTION intents. The thing is that the receiver was giving 3 actions, one of which was what I was looking for! I had to be more careful. – klitemnistra Jul 21 '14 at 08:24