Android 中的 Wifi 身份验证错误

发布于 2024-12-05 09:31:21 字数 194 浏览 2 评论 0原文

我正在 Android 中使用 Wifi 开发一个应用程序。每当我在连接 wifi 时输入错误密码时,我都不会收到任何无效身份验证的通知。它只是不断重试连接。在 wifi 无线设置中也发现了相同的行为。

有什么办法可以发现Wifi认证失败吗?

WifiManager.EXTRA_SUPPLICANT_ERROR - 我从来没有得到这个..

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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清引 2024-12-12 09:31:21

这段代码的工作原理:

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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文