我如何以编程方式尝试使用 WPS 协议连接到 wifi?我找到了如何连接 WEP、WPA 和打开 wifi,但不是 WPS...
谢谢大家!
在回答 Greg432 后编辑
我试过这段代码,但它不起作用,解决方案?
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);
}