示例#1
0
 // 实时获取 wifiSSID
 public boolean findSSID(String ssid) {
   mWifiManager.startScan();
   List<ScanResult> wifiList = mWifiManager.getScanResults(); // ? ?
   for (int i = 0; i < wifiList.size(); i++) {
     ScanResult wifi = wifiList.get(i);
     if (wifi.SSID.equals(ssid)) {
       return true;
     }
   }
   return false;
 }
示例#2
0
 // 添加指定WIFI的配置信息,原列表不存在此SSID
 public int AddWifiConfig(List<ScanResult> wifiList, String ssid, String pwd) {
   int wifiId = -1;
   for (int i = 0; i < wifiList.size(); i++) {
     ScanResult wifi = wifiList.get(i);
     if (wifi.SSID.equals(ssid)) {
       Log.i(TAG, "equals");
       WifiConfiguration wifiCong = new WifiConfiguration();
       wifiCong.SSID = "\"" + wifi.SSID + "\""; // \"转义字符,代表"
       wifiCong.preSharedKey = "\"" + pwd + "\""; // WPA-PSK密码
       wifiCong.hiddenSSID = false;
       wifiCong.status = WifiConfiguration.Status.ENABLED;
       wifiId =
           localWifiManager.addNetwork(wifiCong); // 将配置好的特定WIFI密码信息添加,添加完成后默认是不激活状态,成功返回ID,否则为-1
       if (wifiId != -1) {
         return wifiId;
       }
     }
   }
   return wifiId;
 }
示例#3
0
 // 保持一个wifi信息
 public int AddWifiConfig(String ssid, String pwd) {
   int wifiId = -1;
   mWifiManager.startScan();
   List<ScanResult> wifiList = mWifiManager.getScanResults(); // ????????
   // mWifiManager.re
   for (int i = 0; i < wifiList.size(); i++) {
     ScanResult wifi = wifiList.get(i);
     if (wifi.SSID.equals(ssid)) {
       Log.i("AddWifiConfig", "equals");
       WifiConfiguration wifiCong = new WifiConfiguration();
       wifiCong.SSID = "\"" + wifi.SSID + "\""; // \"????????"
       wifiCong.preSharedKey = "\"" + pwd + "\""; // WPA-PSK????
       wifiCong.hiddenSSID = false;
       wifiCong.status = WifiConfiguration.Status.ENABLED;
       wifiId =
           mWifiManager.addNetwork(
               wifiCong); // ?????ú?????WIFI??????????,????????????????????????????ID???????-1
       if (wifiId != -1) {
         return wifiId;
       }
     }
   }
   return wifiId;
 }