现在我的程序可以通过wifi搜索到很多热点,包括自家的路由器,家里的路由器已经加密了。我肯定知道密码。
现在的问题是,我如何通过编程能够实现这样一个功能:1.判断家里的路由器是不是加密了
2.如果加密了当点击进行连接的时候就跳出一个对话框输入密码然后进行连接。各位大仙 大牛 这个问题困扰好久了,一直没有找到解决问题的办法。谁能指点指点??

解决方案 »

  1.   

    参考下WifiManager 和 WifiConfiguration 两个类
           WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);  
           WifiConfiguration wc = new WifiConfiguration();  
           wc.SSID = "\"SSIDName\"";  
           wc.preSharedKey  = "\"password\"";  
           wc.hiddenSSID = true;  
           wc.status = WifiConfiguration.Status.ENABLED;          
           wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);  
           wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);  
           wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);  
           wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);  
           wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);  
           wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);  
           int res = wifi.addNetwork(wc);  
           Log.d("WifiPreference", "add Network returned " + res );  
           boolean b = wifi.enableNetwork(res, true);          
           Log.d("WifiPreference", "enableNetwork returned " + b ); 
      

  2.   

    WifiManager 已经提供了搜索无线路由获取网络配置等接口的了
    你懒得设置可以直接调用系统的wifi设置activity    Intent it = new Intent(); 
        it.setAction(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
                  // android.provider.Settings.ACTION_WIFI_SETTINGS
                  // android.provider.Settings.ACTION_WIFI_IP_SETTINGS
        this.startActivityForResult(it,0); 
      

  3.   

    Quote=引用 3 楼 xinke87 的回复:]
    1.判断家里的路由器是不是加密了????
    [/Quote]
    public class WifiManagerboolean  startScan() 
    Request a scan for access points. List<ScanResult>  getScanResults() 
    Return the results of the latest access point scan. 
    public class ScanResultFields 
    public String BSSID The address of the access point. 
    public String SSID The network name. 
    public String capabilities   Describes the authentication, key management, and encryption schemes supported by the access point. 
    public int frequency The frequency in MHz of the channel over which the client is communicating with the access point. 
    public int level The detected signal level in dBm.