Ming Chi
Ming Chi

Reputation: 1

How to connect to the specified BSSID?

In my case, i want to change AP connection. In my environment, there are two identical AP names, but their BSSID is different. Before android 6.0, My application works fine.

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.

How can i connect to the specified BSSID?

Upvotes: 0

Views: 2216

Answers (1)

VelocityPulse
VelocityPulse

Reputation: 632

you can connect your phone to a specific BSSID by the following code :

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();

Upvotes: 1

Related Questions