简体   繁体   English

如何连接到指定的BSSID?

[英]How to connect to the specified BSSID?

In my case, i want to change AP connection. 就我而言,我想更改AP连接。 In my environment, there are two identical AP names, but their BSSID is different. 在我的环境中,有两个相同的AP名称,但是它们的BSSID不同。 Before android 6.0, My application works fine. 在android 6.0之前,我的应用程序可以正常工作。

In android 6.0, I chose one of the two AP names, android has disconnect successful, but after the Android reconnect, it is always connected to the original connection. 在android 6.0中,我选择了两个AP名称之一,android已成功断开连接,但在Android重新连接后,它始终连接到原始连接。

How can i connect to the specified BSSID? 如何连接到指定的BSSID?

you can connect your phone to a specific BSSID by the following code : 您可以通过以下代码将手机连接到特定的BSSID:

WifiManager mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); 
WifiConfiguration mWifiConfiguration = new WifiConfiguration();

mWifiConfiguration.SSID = "\"" + your_SSID + "\"";
mWifiConfiguration.BSSID = your_BSSID;
mWifiConfiguration.preSharedKey = "\"" + your_password + "\"";

mWifiConfiguration.status = WifiConfiguration.Status.ENABLED;
mWifiConfiguration.priority = 99999;
int myNetworkId = mWifiManager.addNetwork(mWifiConfiguration);

mWifiManager.disconnect();
mWifiManager.updateNetwork(mWifiConfiguration);
mWifiManager.enableNetwork(myNetworkId, true);
mWifiManager.reconnect();

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

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