简体   繁体   English

检查wifi凭据是否已在设备上连接WIFI SSID

[英]Checking wifi credentials if WIFI SSID was already connected on a device

Situation: 1) I have android device already successfully connected to my SSID so password is stored, and it connects well. 情况:1)我已经将Android设备成功连接到我的SSID,因此密码已存储,并且连接良好。 2) In my application I have option for user to input wifi credential for this network (SSID is determined here no problem, but password without root cannot be determined, so user input it manually) 2)在我的应用程序中,我可以选择用户为此网络输入wifi凭据(确定SSID没问题,但无法确定没有root的密码,因此用户手动输入)

Problem: After user input wifi password - i need to check if password is correct - only the way to check this is connect to this wifi network - How to do this correctly? 问题:用户输入wifi密码后-我需要检查密码是否正确-唯一的检查方法是连接到此wifi网络-如何正确执行此操作?

What tried: When I disconnect from wifi ssid, and i add config for wifi with credential user input - even if it's bad password - wifi reconnects successful, coz i guess previously entered credentials from config outside of my application was correct. 尝试了什么:当我从wifi ssid断开连接,并且使用凭据用户输入添加wifi的配置时-即使密码错误-wifi重新连接成功,因为我猜以前我从应用程序外部的配置中输入了凭据是正确的。 So whatever password user will input - in connects in anyway and i cannot know if credential user entered is correct. 因此,无论用户输入什么密码,无论如何都可以连接,我不知道输入的凭据用户是否正确。

Any help - welcome! 任何帮助-欢迎光临! Thanks. 谢谢。

Finally guys after several hours of research was able to determine next: 经过几个小时的研究,终于可以确定下一步:

Pre conditions: 1) device is connected to wifi network with standard device options with right password; 前提条件:1)使用正确的密码通过标准设备选项将设备连接到wifi网络; 2) M trying to check user entered credentials for this wifi network. 2)M试图检查用户为此wifi网络输入的凭据。

Results: Warn! 结果:警告! (only exact flow of actions is working for me): (只有确切的操作流程对我有用):

1) disconnect from wifi: 1)断开与wifi的连接:

wifiManager.disconnect();

2) create configuration: 2)创建配置:

WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + wifiSsid + "\"";
if(authType == 0){
    conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
} else if(authType == 1) {
    conf.preSharedKey = "\""+ wifiPassword+"\"";
    conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
} else {
    conf.preSharedKey = "\""+ wifiPassword+"\"";
}
conf.status = WifiConfiguration.Status.ENABLED;

3) disable and remove all configs (actually they will not be removed if not created in your aplication): 3)禁用并删除所有配置(实际上,如果未在应用程序中创建它们,则不会将它们删除):

 List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
 for (WifiConfiguration i : list) {
     wifiManager.disableNetwork(i.networkId);
     wifiManager.removeNetwork(i.networkId);
 }

4) add created config: 4)添加创建的配置:

final int networkId = wifiManager.addNetwork(conf);

5) Activate config but only with this command: 5)激活配置,但只能使用以下命令:

wifiManager.enableNetwork(networkId, true);

What is in result, if wifi password in config is correct you get connection to wifi in around 2 - 4 seconds, but if password from wifi in config is wrong - you get connected (if this network was connected before via settings) much longer around 8 - 12 seconds. 结果是,如果config中的wifi密码正确,则您将在2-4秒钟内连接到wifi,但是如果config中的wifi密码不正确-您将获得更长的连接时间(如果通过设置连接了此网络) 8-12秒。

Here is you are not connected in 2-4 seconds, you can write that wifi credentials check failed or connect to network failed. 这是您在2-4秒钟内没有连接,您可以写wifi凭证检查失败或连接到网络失败。

I requested from google developers feature to wifi manager to check credentials ability, But for now for me this is all that could be done. 我要求Google开发人员功能向wifi管理器检查凭据功能,但是就我而言,这是可以完成的全部工作。

Guys, any other solutions welcome! 伙计们,欢迎其他解决方案!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM