9

I am developing an application using Wifi in Android. Whenever I enter wrong password while connecting to wifi, I dont get any notification for invalid authentication. It just keeps on retrying to connect. Same behavior is found in wifi wireless setting.

Is there any way to find that Wifi Authentication has failed??

WifiManager.EXTRA_SUPPLICANT_ERROR -- I never get this..

David Olsson
  • 8,085
  • 3
  • 30
  • 38
Bhushan Kini
  • 91
  • 1
  • 3

1 Answers1

17

This code works:

IntentFilter mIntentFilter = new IntentFilter();
mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
registerReceiver(receiverWifi, mIntentFilter);


class WifiReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context c, Intent intent) {
        String action  = intent.getAction();
        if(action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)){
            Log.d("WifiReceiver", ">>>>SUPPLICANT_STATE_CHANGED_ACTION<<<<<<");
            SupplicantState supl_state=((SupplicantState)intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE));
            switch(supl_state){
            case ASSOCIATED:Log.i("SupplicantState", "ASSOCIATED");
                break;
            case ASSOCIATING:Log.i("SupplicantState", "ASSOCIATING");
                break;
            case AUTHENTICATING:Log.i("SupplicantState", "Authenticating...");
                break;
            case COMPLETED:Log.i("SupplicantState", "Connected");
                break;
            case DISCONNECTED:Log.i("SupplicantState", "Disconnected");
                break;
            case DORMANT:Log.i("SupplicantState", "DORMANT");
                break;
            case FOUR_WAY_HANDSHAKE:Log.i("SupplicantState", "FOUR_WAY_HANDSHAKE");
                break;
            case GROUP_HANDSHAKE:Log.i("SupplicantState", "GROUP_HANDSHAKE");
                break;
            case INACTIVE:Log.i("SupplicantState", "INACTIVE");
                break;
            case INTERFACE_DISABLED:Log.i("SupplicantState", "INTERFACE_DISABLED");
                break;
            case INVALID:Log.i("SupplicantState", "INVALID");
                break;
            case SCANNING:Log.i("SupplicantState", "SCANNING");
                break;
            case UNINITIALIZED:Log.i("SupplicantState", "UNINITIALIZED");
                break;
            default:Log.i("SupplicantState", "Unknown");
                break;

            }
            int supl_error=intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, -1);
            if(supl_error==WifiManager.ERROR_AUTHENTICATING){
                Log.i("ERROR_AUTHENTICATING", "ERROR_AUTHENTICATING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            }
        }
    }
}

<receiver
    android:name=".MyActivity$WifiReceiver"
    android:process=":remote" >
</receiver>
ahtartam
  • 879
  • 9
  • 13
  • 4
    It doesn't seem to be 100% reliable though. – Eric Woodruff Mar 22 '14 at 05:09
  • 1
    @ahtartam How to know to which ssid this supplicantstate is talking about ? – Rohit Sharma Feb 25 '15 at 17:03
  • `int supl_error=intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, -1); if(supl_error==WifiManager.ERROR_AUTHENTICATING){ Log.i("ERROR_AUTHENTICATING", "ERROR_AUTHENTICATING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); }` my code does not go through this if statement because the supl_error is always -1 , even when trying to connect to a wifi entering an invalid password. Any ideas? Thank you. .Note: When I successfully connected to wifi, I receive the supl_state COMPLETED, the only problem is the suppl_error when failed to authenticate with invalid PW. – Andrin Danganan Apr 25 '18 at 04:49