Android的 - 看看密码的wifi是正确的 [英] Android - see if password to wifi was correct

查看:384
本文介绍了Android的 - 看看密码的wifi是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算做如果某无线网络使用共同的密码,检查应用程序。我最常用的密码列表,但以下功能:

I plan to make an app that checks if a certain wifi network uses common password. I have a list of most common passwords, but the following function:

public boolean connectTo(String psKey){
    WifiConfiguration wc = new WifiConfiguration();
    wc.SSID = "\"" + dbw.getSsid() + "\"";
    wc.preSharedKey  = "\"" + psKey + "\"";

    wc.status = WifiConfiguration.Status.ENABLED;   
    wc = configureCapabs(wc, dbw.getCapability());

    int res = wifi.addNetwork(wc);
    Toast.makeText(this, "add Network returned " + res , Toast.LENGTH_SHORT).show();
    boolean b = wifi.enableNetwork(res, true);        
    Toast.makeText(this, "enableNetwork returned " + b , Toast.LENGTH_SHORT).show();
    if(!b) return false;
    boolean fin = /*b ? wifi.reassociate() : */wifi.reconnect();
    return fin;
}

返回true,即使密码是不正确的。是否有检查,如果我试图与登录密码被接受或拒绝的方式?

it returns true, even if the password was incorrect. Is there a way of checking if the password that I tried to log in with was accepted or rejected?

推荐答案

正在使用重新连接() / 重新关联() WiFiManager 的方法来检查天气或没有成功连接,但布尔值,他们返回意味着别的东西。返回值只告诉你开始给定操作的结果。这是因为关联并连接到WiFi网络需要时间。这些方法但是会立即返回,并不会阻止。连接或与网络相关联的实际任务是在后台异步完成

You are using the reconnect() / reassociate() methods of WiFiManager to check weather or not the connection succeeded but the boolean value that they return means something else. The returned value only tells you about the result of STARTING a given operation. This is because associating and connecting to a WiFi network takes time. These methods however will return instantly and will not block. The actual task of connecting or associating with the network is done asynchronously in the background.

您可以监控的是与通过监听到一个特定的系统范围内的广播WiFi连接发生的事情:

You can monitor the what is happening with the WiFi connection by listening to a specific system wide broadcast:

<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<action android:name="android.net.wifi.STATE_CHANGE"/>

您可以找到更多这方面的信息<一个href=\"http://stackoverflow.com/questions/5276032/connectivity-action-intent-recieved-twice-when-wifi-connected\">HERE - 检查托斯滕的答案

You can find more info about this HERE - Check Torsten's answer.

这篇关于Android的 - 看看密码的wifi是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆