What is the way to forget the old Wi-Fi network saved and delete connection file in android 6 and higher?
Asked
Active
Viewed 745 times
1 Answers
1
If want to forget the old wifi network saved , you can follow bellow ways to have a try :
public void RemoveWiFi()
{
WifiManager mWifiManager = (WifiManager)GetSystemService(Context.WifiService);
WifiConfiguration mWifiConfig = new WifiConfiguration();
List<WifiConfiguration> conlist = (List<WifiConfiguration>)mWifiManager.ConfiguredNetworks;//获取保存的配置信息
for (int i = 0; i < conlist.Count; i++)
{
Log.Debug("Tag", "i = " + i + "SSID = " + conlist[i].Ssid + " netId = " + conlist[i].NetworkId);
// Forget the specified wifi
// if (conlist[i].Ssid == "xxx") { ... }
// Forget the current connected wifi
if ( i == 0 )
{
mWifiManager.RemoveNetwork(conlist[i].NetworkId);
}
}
}
Not forget to add permissions in AndroidManifest.xml :
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Note :
You need to turn the app into a system app and give system permissions .
- Modify the
AndroidManifest.xml
:
...
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=xxxx"
android:sharedUserId="android.uid.system"
coreApp="true">
<application
android:process="system"
/>
- Install app bellow
/system/app
folder in Android device .

Junior Jiang
- 12,430
- 1
- 10
- 30
-
hi Junior Jiang .When placing the code inside the button and pressing the application stops Note that I gave the permission – ALIE Jun 22 '20 at 06:34
-
@ALIE Okey ,could you share the error logs here ? And whehter test it in a physical device . – Junior Jiang Jun 22 '20 at 06:37
-
@ALIE Hi , sorry for noting that . This method needs to turn the app into a system app and give system permissions . – Junior Jiang Jun 22 '20 at 06:45
-
I used the following method after placing the void buttona.Click += delegate { RemoveWiFi(); }; – ALIE Jun 22 '20 at 06:54
-
@ALIE I have updated answer , also need the system permission . Because from Android 6.0 , not allows private app to remove wifi configuration. – Junior Jiang Jun 22 '20 at 07:00
-
I will try the code on the phone after the amendment and talk back to you – ALIE Jun 22 '20 at 07:02
-
Could you please help me by raising an example of github – ALIE Jun 22 '20 at 07:04
-
@ALIE Sorry for can not showing with github , because it nees ROOT in Android Device . About System application , refer to : https://stackoverflow.com/questions/17222535/create-system-application – Junior Jiang Jun 22 '20 at 07:12