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