0

I want to forget the wifi connected network from the device.I gone through most of the code but they are not working.

 public void disconnectWifi(){
        Log.i(TAG,"In disconnectWifi()");
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        wifiManager.forget(wifiInfo.getNetworkId(), new WifiManager.ActionListener() {
            @Override
            public void onSuccess() {
                Log.i(TAG,"wifi is disconnected");
            }

           @Override
            public void onFailure(int reason) {
                Log.i(TAG,"wifi is failed disconnected");
            }
        });
    }

Here on Success is never called.

public void disconnectCurrentNetwork(){
        WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        if(wifiManager != null && wifiManager.isWifiEnabled()){
            List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
            Log.d(TAG,"lIST"+list);
            int netId = wifiManager.getConnectionInfo().getNetworkId();
            wifiManager.removeNetwork(netId);
        }

    }

Here netid shows -1 value and it also not forget the wifi network. I have read that it should not work you must use have to provide permission WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN.I also mention that in manifest as below but no changes happpens.I have read that Your apps can now change the state of WifiConfiguration objects only if you created these objects. You are not permitted to modify or delete WifiConfiguration objects created by the user or by other apps. Since we can forget network by going to the settings of mobile.So there should be some method to forget the WiFi network

  <uses-permission android:name="WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN"/>
gopssays
  • 41
  • 7
  • "Since we can forget network by going to the settings of mobile." - who is "we"? User can go to Settings and remove WiFi conn params, just like can navigate to all apps and uninstall any or enable/disable `AccessibilityService`. That doesn't mean that you, as developer, can achieve same things... and `WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN` isn't a permission, so your ` – snachmsm Feb 23 '22 at 06:50
  • @snachmsm-Do you know how to use WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, to achieve this. – gopssays Feb 23 '22 at 06:53
  • afaik all these values can't be changes, these are read only. They can't be changed due to privacy and security policy, you just can't set `ADB_ENABLED`, `AIRPLANE_MODE_ON`, `DEVICE_NAME` and all other listed in [`Settings.Global`](https://stackoverflow.com/questions/22474959/how-to-use-settings-global-class-in-android) – snachmsm Feb 23 '22 at 07:46

0 Answers0