public static void disconnect() {
   List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
   for (WifiConfiguration i : list) {
     if (i.SSID.equals(FirstSettings_two.first_ssid)) {
       WifiConfiguration conf = new WifiConfiguration();
       conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
       conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
       wifiManager.disconnect();
       break;
     }
   }
 }
  public static void reconnect1() {
    try {
      List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
      for (WifiConfiguration i : list) {
        if (i.SSID.equals(FirstSettings_two.first_ssid)) {
          wifiManager.enableNetwork(i.networkId, true);
          wifiManager.reconnect();

          break;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    ;
  }
 public void reconnect5() {
   try {
     List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
     for (WifiConfiguration i : list) {
       if (i.SSID.equals(FirstSettings_two.first_ssid)) {
         wifiManager.enableNetwork(i.networkId, true);
         wifiManager.reconnect();
         File_Video downloadFile_video = new File_Video();
         downloadFile_video.execute(BroadcastNewSms.filepath);
         break;
       }
     }
   } catch (Exception e) {
     Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
   }
   ;
 }
示例#4
0
  void Connect() {
    Log.i("starwisp", "Attemping connect to " + SSID);

    List<WifiConfiguration> list = wifi.getConfiguredNetworks();

    Boolean found = false;

    for (WifiConfiguration i : list) {
      if (i.SSID != null && i.SSID.equals("\"" + SSID + "\"")) {
        found = true;
        Log.i("starwisp", "Connecting (state=connected)");
        state = State.CONNECTED;
        wifi.disconnect();
        wifi.enableNetwork(i.networkId, true);
        wifi.reconnect();
        Log.i("starwisp", "Connected");
        try {
          Thread.sleep(2000);
          Log.i("starwisp", "trying post-connection callback");
          m_Builder.DialogCallback(m_Context, m_Context.m_Name, m_CallbackName, "\"Connected\"");
        } catch (Exception e) {
          Log.i("starwisp", e.toString());
          e.printStackTrace();
        }

        break;
      }
    }

    if (!found) {
      Log.i("starwisp", "adding wifi config");
      WifiConfiguration conf = new WifiConfiguration();
      conf.SSID = "\"" + SSID + "\"";

      // conf.wepKeys[0] = "\"" + networkPass + "\"";
      // conf.wepTxKeyIndex = 0;
      // conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
      // conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);

      conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
      wifi.addNetwork(conf);
    }
  }