jeudi 22 mai 2014

Programmation Androïd : Obtention des réseaux Wifi connus

    WifiManager myWifiManager = null;


    public void getConfiguredNetworks(){


        try {
            myWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        } catch (Exception e) {
            //log("Exception:" + e.getMessage());
        }

        if ((myWifiManager!=null) && (myWifiManager.isWifiEnabled()==true)){
            log("Getting configured networks...");
            List<WifiConfiguration> lstWifiConfiguration = myWifiManager.getConfiguredNetworks();
            for(int i=0;i<lstWifiConfiguration.size();i++){
                WifiConfiguration wifiConfiguration = lstWifiConfiguration.get(i);
                log("Config" + i + ":SSID="+wifiConfiguration.SSID);
                log("Config" + i + ":   BSSID="+wifiConfiguration.BSSID);
                log("Config" + i + ":   preSharedKey="+wifiConfiguration.preSharedKey);
                String[] strWepKeys = wifiConfiguration.wepKeys;
                for(int j=0;j<strWepKeys.length;j++){
                    log("Config" + i + ":   WepKey" + j + ":" + strWepKeys[j]);
                }
            }
        }
    }