-1
if (Build.VERSION.SDK_INT >= 23) { 

      wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); 
      wifi.startScan(); 

      ///////////////////// 
      beforeOpenDoorWifi = wifi.getConnectionInfo().getNetworkId(); 
      wifi.setWifiEnabled(true); 
      // setup a wifi configuration 
      WifiConfiguration wc = new WifiConfiguration(); 

      List lst = wifi.getConfiguredNetworks(); 


      wc.SSID = "\"" + sSid + "\""; 
      wc.preSharedKey = "\"" + pass + "\""; 

      wc.status = WifiConfiguration.Status.DISABLED; 
      wc.priority = 40; 
      wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN); 
      wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA); 
      wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); 
      wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); 
      wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); 
      wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); 
      wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); 
      wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); 
      wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); 

      // connect to and enable the connection 

      int netId = wifi.addNetwork(wc); 
      if (-1 == netId) { 
       // enableWifi(wifiName); 

       List<WifiConfiguration> llst = wifi.getConfiguredNetworks(); 
       Iterator<WifiConfiguration> it = llst.iterator(); 
       while (it.hasNext()) { 
        WifiConfiguration wconfig = it.next(); 
        if (wconfig.SSID.equals("\"" + sSid + "\"")) { 
         wifi.enableNetwork(wconfig.networkId, true); 

         setFalseOther(mm); 
         notifyDataSetChanged(); 
         mSession.setPrefrenceString("networkName", sSid); 
         Intent i = new Intent(mContext, Connect.class); 
         i.putExtra("networkName", mm.getName()); 
         i.putExtra("networkId", mm.getId()); 
         i.putExtra("AdminID", mm.getUserId()); 
         i.putExtra("networkConnection", "true"); 

         mContext.startActivity(i); 

         break; 
        } 
       } 

이 코드는 주어진 SSID 및 암호로 연결하는 데는 문제가 없지만 네트워크 세부 정보를 연결 해제하거나 제거하고 싶습니다. "disableNetwork (networkId)"는 도움이되지 않습니다. 어느 누구라도 marshmallow에서 wifi 네트워크를 연결, 연결 해제 또는 제거하는 데 더 나은 솔루션을 제공 할 수 있다면 도움이 될 것입니다. 미리 감사드립니다.android marshmallow에서 특정 와이파이 네트워크를 제거하거나 연결을 끊으시겠습니까?

답변

0
 public void forget(final String s) { 
    final WifiConfiguration wifiConfigure = this.getWifiConfigure(s); 
    if (wifiConfigure != null) { 
     final Method[] declaredMethods = this.mWifiManager.getClass().getDeclaredMethods(); 
     Boolean b = false; 
     for (final Method method : declaredMethods) { 
      if (method.getName().equals("forget")) { 
       b = true; 
       try { 

        method.invoke(this.mWifiManager, wifiConfigure.networkId, null); 
       } 
       catch (Exception ex) { 
        b = false; 
       } 
       break; 
      } 
     } 
     if (!b) { 
      this.disableAndRemoveWifi(s); 
     } 
    } 
}