1

我可以使用以下方法添加网络,但如果在和之后添加或失败,code则无法获取状态。请帮忙!!!authenticationEnable Networkreconnect

 mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
            removeNetwork();

        Boolean isWifiConnected = false;

        WifiConfiguration mWifiConf = new WifiConfiguration();          
        mWifiConf.SSID = "\"" + networkList.get(item_pos).SSID + "\"";
        mWifiConf.hiddenSSID = true;
        mWifiConf.status = WifiConfiguration.Status.ENABLED;  
        mWifiConf.priority = 1;         
        if(addWPA2Network(mWifiConf, etPassword.getText().toString())<0)
        {

        }
        else
        {
            List<WifiConfiguration> list = mWifiManager.getConfiguredNetworks();

            for (WifiConfiguration i : list) 
            {
                if (i.SSID != null && i.SSID.equals("\"" + networkList.get(item_pos).SSID + "\"")) 
                {
                    mWifiManager.disconnect();
                    isWifiConnected = mWifiManager.enableNetwork(i.networkId, true);
                    isWifiConnected = mWifiManager.reconnect();                 

                    break;
                }
            }
        }
4

2 回答 2

0

将网络的 android 权限添加到清单文件中。

于 2013-04-15T13:32:16.493 回答
0

从这个链接得到我的答案:https ://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/wifi/WifiStatusTest.java

if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
                handleSupplicantStateChanged(
                        (SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),
                        intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR),
                        intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, 0));
            }

使用此处理程序检查其连接是否成功。

于 2013-04-16T07:37:15.400 回答