Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the SSID of all configured WiFi networks programmatically?

I want to get all WiFi detail which i have added password.

Code:

WifiManager wifiManager = (WifiManager) getApplicationContext()
    .getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> configuredList = wifiManager.getConfiguredNetworks();
like image 916
DevThapa Avatar asked Nov 04 '16 18:11

DevThapa


1 Answers

EDIT: WifiConfiguration is deprecated since API level 29, from its docs:

This class was deprecated in API level 29. Use WifiNetworkSpecifier.Builder to create NetworkSpecifier and WifiNetworkSuggestion.Builder to create WifiNetworkSuggestion. This will become a system use only object in the future.

Original (outdated) answer:

You can simply get the SSID from the public SSID field of WifiConfiguration:

List<String> ssidList = new ArrayList<>();

for(WifiConfiguration config : configuredList) {
    ssidList.add(config.SSID);
}

Don't forget to add the ACCESS_WIFI_STATE permission to your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
like image 100
earthw0rmjim Avatar answered Oct 05 '22 12:10

earthw0rmjim