Network Status is Missing

為{幸葍}努か 提交于 2019-12-11 11:45:04

问题


I'm able to add network using following code but not able to get status if its added or authentication failed after Enable Network and reconnect. Please help!!!

 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;
                }
            }
        }

回答1:


Add the android permissions for network to the manifest file.




回答2:


Got my answer from this link: 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));
            }

Use this handler to check if its connected successfully or not.



来源:https://stackoverflow.com/questions/16014819/network-status-is-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!