how i can try a connection to a wifi with WPS protocol programmatically? I have found how connect with WEP, WPA and open wifi, but not WPS...
Thanks all!
EDIT AFTER ANSWER OF Greg432
I have try this code but it don't work, solution?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
wpsInfo = new WpsInfo();
wpsInfo.BSSID = wifiList.get(0).BSSID;
wpsInfo.pin = "11883737";
wpsInfo.setup = 0;
wpsCallback = new WifiManager.WpsCallback() {
@Override
public void onStarted(String pin) {
Toast.makeText(getApplicationContext(), "Started wps connection.", Toast.LENGTH_SHORT).show();
}
@Override
public void onSucceeded() {
Toast.makeText(getApplicationContext(), "Connected!", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(int reason) {
String errorMessage;
switch (reason) {
case WifiManager.WPS_OVERLAP_ERROR:
errorMessage = "WPS_OVERLAP_ERROR";
break;
case WifiManager.WPS_WEP_PROHIBITED:
errorMessage = "WPS_WEP_PROHIBITED";
break;
case WifiManager.WPS_TKIP_ONLY_PROHIBITED:
errorMessage = "WPS_WEP_PROHIBITED";
break;
/*case WifiManager.IN_PROGRESS:
mWifiManager.cancelWps(null);
startWps();
return;*/
case WifiManager.WPS_TIMED_OUT:
errorMessage = "WPS_TIMED_OUT";
//startWps();
return;
default:
errorMessage = "Generic error.";
break;
}
Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_SHORT).show();
}
};
wifiManager.startWps(wpsInfo, wpsCallback);
}
Use the WifiManager's startWps() method:
mWifiManager.startWps(wpsConfig, mWpsCallback);
You should pass a configuration and a callback.
Example
Update 2021
Connecting with WPS programatically is deprecated and removed as of API 28 and above.
It is no longer possible to connect with mWifiManager.startWps(wpsConfig, mWpsCallback);
And there are also no alternatives.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.