How to get wifi configuration file location in android

I am developing an application that backs up the wifi configuration from any Android device (rooted) so I want to know how to get the location of the file on the Android device, so I can deal with it.

I know that there are many places depending on your ROM or device

like /data/wifi/bcm_supp.conf or /data/misc/wifi/wpa_supplicant.conf

but I want to get it dynamically.

+7
source share
1 answer

You need to create an instance of WifiConfiguration as follows:

 String networkSSID = "test"; String networkPass = "pass"; WifiConfiguration conf = new WifiConfiguration(); conf.SSID = "\"" + networkSSID + "\""; // 

Then, for the WEP network, you need to do the following:

 conf.wepKeys[0] = "\"" + networkPass + "\""; conf.wepTxKeyIndex = 0; conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); 

For a WPA network, you need to add this phrase:

 conf.preSharedKey = "\""+ networkPass +"\""; 

For an open network, you need to do this:

  conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); 

Then you need to add it to the settings of the Android Wi-Fi manager:

 WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiManager.add(conf); 

And finally, you may need to enable it, so Android connects to it:

 List<WifiConfiguration> list = wifiManager.getConfiguredNetworks(); for (WifiConfiguration i : list) { if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) { wm.disconnect(); wm.enableNetwork(i.networkId, true); wm.reconnect(); break; } } 

In the case of WEP, if your password is in hexadecimal, you do not need to surround it with quotation marks.

+3
source

All Articles