移除或断开android棉花糖中的特定wifi网络? if(Build.VERSION.SDK\u INT>=23){ wifi=(WifiManager)mContext.getSystemService(Context.wifi\u SERVICE); wifi.startScan(); ///////////////////// beforeOpenDoorWifi=wifi.getConnectionInfo().getNetworkId(); wifi.setWifiEnabled(true); //设置wifi配置 WifiConfiguration wc=新的WifiConfiguration(); List lst=wifi.getConfiguredNetworks(); wc.SSID=“\”+SSID+“\”; wc.preSharedKey=“\”+通过+“\”; wc.status=WifiConfiguration.status.DISABLED; wc.priority=40; wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA); wc.allowedKeyManagement.set(wificonfig.keymanagement.WPA\u PSK); wc.allowedPairwisecipher.set(WifiConfiguration.Pairwiseciper.CCMP); wc.allowedPairwisecipher.set(WifiConfiguration.Pairwiseciper.TKIP); AlloweGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); AlloweGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); AlloweGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); AlloweGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); //连接到并启用连接 int netId=wifi.addNetwork(wc); 如果(-1==netId){ //启用WiFi(wifiName); List llst=wifi.getConfiguredNetworks(); 迭代器it=llst.Iterator(); while(it.hasNext()){ WifiConfiguration wconfig=it.next(); 如果(wconfig.SSID.equals(“\”+SSID+“\”)){ wifi.enableNetwork(wconfig.networkId,true); 其他(毫米); notifyDataSetChanged(); mSession.setPrefrenceString(“网络名称”,sSid); 意图i=新意图(mContext,Connect.class); i、 putExtra(“networkName”,mm.getName()); i、 putExtra(“networkId”,mm.getId()); i、 putExtra(“AdminID”,mm.getUserId()); i、 putExtra(“网络连接”,“真”); mContext.startActivity(i); 打破 } }
此代码适用于连接到给定的SSID和密码,但我想断开或删除该网络详细信息。“disableNetwork(networkId)”不会提供任何帮助。如果任何人能够提供更好的连接解决方案,断开或删除棉花糖中的wifi网络将非常有用。提前感谢移除或断开android棉花糖中的特定wifi网络? if(Build.VERSION.SDK\u INT>=23){ wifi=(WifiManager)mContext.getSystemService(Context.wifi\u SERVICE); wifi.startScan(); ///////////////////// beforeOpenDoorWifi=wifi.getConnectionInfo().getNetworkId(); wifi.setWifiEnabled(true); //设置wifi配置 WifiConfiguration wc=新的WifiConfiguration(); List lst=wifi.getConfiguredNetworks(); wc.SSID=“\”+SSID+“\”; wc.preSharedKey=“\”+通过+“\”; wc.status=WifiConfiguration.status.DISABLED; wc.priority=40; wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA); wc.allowedKeyManagement.set(wificonfig.keymanagement.WPA\u PSK); wc.allowedPairwisecipher.set(WifiConfiguration.Pairwiseciper.CCMP); wc.allowedPairwisecipher.set(WifiConfiguration.Pairwiseciper.TKIP); AlloweGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); AlloweGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); AlloweGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); AlloweGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); //连接到并启用连接 int netId=wifi.addNetwork(wc); 如果(-1==netId){ //启用WiFi(wifiName); List llst=wifi.getConfiguredNetworks(); 迭代器it=llst.Iterator(); while(it.hasNext()){ WifiConfiguration wconfig=it.next(); 如果(wconfig.SSID.equals(“\”+SSID+“\”)){ wifi.enableNetwork(wconfig.networkId,true); 其他(毫米); notifyDataSetChanged(); mSession.setPrefrenceString(“网络名称”,sSid); 意图i=新意图(mContext,Connect.class); i、 putExtra(“networkName”,mm.getName()); i、 putExtra(“networkId”,mm.getId()); i、 putExtra(“AdminID”,mm.getUserId()); i、 putExtra(“网络连接”,“真”); mContext.startActivity(i); 打破 } },android,android-wifi,android-6.0-marshmallow,wifi,Android,Android Wifi,Android 6.0 Marshmallow,Wifi,此代码适用于连接到给定的SSID和密码,但我想断开或删除该网络详细信息。“disableNetwork(networkId)”不会提供任何帮助。如果任何人能够提供更好的连接解决方案,断开或删除棉花糖中的wifi网络将非常有用。提前感谢 if (Build.VERSION.SDK_INT >= 23) { wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
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;
}
}
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);
}
}
}