Example usage for android.net.wifi WifiManager removeNetwork

List of usage examples for android.net.wifi WifiManager removeNetwork

Introduction

In this page you can find the example usage for android.net.wifi WifiManager removeNetwork.

Prototype

public boolean removeNetwork(int netId) 

Source Link

Document

Remove the specified network from the list of configured networks.

Usage

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean setWifiRemoveSsid(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) {
    WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE);
    int nwid = wm.getConnectionInfo().getNetworkId();
    if (envParms.isWifiConnected()) {
        if (!envParms.wifiSsid.equals(EnvironmentParms.WIFI_DIRECT_SSID)) {
            wm.removeNetwork(nwid);
            ar.action_resp = ActionResponse.ACTION_SUCCESS;
            ar.resp_msg_text = "";
            return true;
        } else {/*w  w  w .  j av a  2s.  co m*/
            ar.action_resp = ActionResponse.ACTION_WARNING;
            ar.resp_msg_text = "Can not removed, WiFi is connected to WiFi-Direct";
            return false;
        }
    }
    ar.action_resp = ActionResponse.ACTION_WARNING;
    ar.resp_msg_text = "Wifi not connected";
    return false;
}

From source file:com.landenlabs.all_devtool.NetFragment.java

private void clean_networks() {
    StringBuilder sb = new StringBuilder();
    final WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) {
        try {//from  www.  j a  v a 2  s . c om
            List<WifiConfiguration> listWifiCfg = wifiMgr.getConfiguredNetworks();
            for (WifiConfiguration wifiCfg : listWifiCfg) {

                if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) {

                    // Remove network connections with no Password.
                    if (wifiMgr.removeNetwork(wifiCfg.networkId)) {
                        sb.append(wifiCfg.SSID);
                        sb.append("\n");
                    }
                }
            }
        } catch (Exception ex) {

        }
    }

    if (sb.length() != 0) {
        Toast.makeText(this.getContext(), "Removed Networks: " + sb.toString(), Toast.LENGTH_LONG).show();
    }
}