0
我需要这个代码programaticly连接到新的wifi网络到设备: `新网络添加到Android设备programsticly
try
{
String ssid = "\"" + SSID + "\"";
String pass = "\"" + Pass + "\"";
for (ScanResult result : results)
{
if (result.SSID.equals(SSID))
{
String security = getScanResultSecurity(result);
if (security.equals("PSK")) {
WifiConfiguration con = new WifiConfiguration();
con.SSID = ssid;
AlertDialog a = new AlertDialog.Builder(MainActivity.this).create();
a.setMessage("in");
a.show();
con.preSharedKey = pass;
con.hiddenSSID = true;
con.status = WifiConfiguration.Status.ENABLED;
con.allowedGroupCiphers.set(WifiConfiguration.Grou pCipher.TKIP);
con.allowedGroupCiphers.set(WifiConfiguration.Grou pCipher.CCMP);
con.allowedKeyManagement.set(WifiConfiguration.Key Mgmt.WPA_PSK);
con.allowedPairwiseCiphers.set(WifiConfiguration.P airwiseCipher.TKIP);
con.allowedPairwiseCiphers.set(WifiConfiguration.P airwiseCipher.CCMP);
con.allowedKeyManagement.set(WifiConfiguration.Key Mgmt.NONE);
con.allowedProtocols.set(WifiConfiguration.Protoco l.RSN);
con.allowedProtocols.set(WifiConfiguration.Protoco l.WPA);
int ntid = wifimanager.addNetwork(con);
wifimanager.disconnect();
wifimanager.enableNetwork(ntid,true);
wifimanager.reconnect();
boolean b = wifimanager.saveConfiguration();
if (ntid != -1 && b) {
AlertDialog a2 = new AlertDialog.Builder(MainActivity.this).create();
a2.setMessage("saved");
a2.show();
}
}
}
}
catch (Exception ex) {
AlertDialog a = new AlertDialog.Builder(MainActivity.this).create();
a.setMessage(ex.getMessage());
a.show();
}
'
但我不能添加网络到我的设备 问题与网络配置不能添加到网络 我无法理解,为什么不工作没有erorr但没有结果 帮我请
你的日志说什么? – Aenadon
我无法理解很多消息,最终失败 – Ronix3
这是日志mStopped = false mHashWindowFocus = true sendUserActionEvent()mView = null并且输入事件接收器已被处置 – Ronix3