I thought that I should use NetworkInterface::getDisplayName. I got some name, but this name is different that this name which I can see, when I choosing to which network I want to connect.
Asked
Active
Viewed 5.6k times
62
-
2Does anyone know which permissions are needed to do this? – Paul Alexander Jan 15 '14 at 09:41
-
8android.permission.ACCESS_WIFI_STATE – PHP Avenger Jan 29 '14 at 23:04
4 Answers
46
android.net.wifi.WifiInfo.getSSID
?
WifiManager wifiMgr = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
String name = wifiInfo.getSSID();

Sabito stands with Ukraine
- 4,271
- 8
- 34
- 56

Loxley
- 1,781
- 17
- 20
-
-
I have added the question asker's answer into your answer. I hope that is ok @Loxley. – Sabito stands with Ukraine Mar 05 '21 at 18:26
-
WifiManager is not known in xamarin, do I need to add some packaqe ? And what is `context` ? – GuidoG Dec 03 '22 at 07:43
25
public String getWifiName(Context context) {
WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (manager.isWifiEnabled()) {
WifiInfo wifiInfo = manager.getConnectionInfo();
if (wifiInfo != null) {
DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) {
return wifiInfo.getSSID();
}
}
}
return null;
}
19
This (mix and match of various answers from Marakana and others) will simultaneously get everything you want to extract from:
- all wifi routers in range
- connected wifi router
all stored wifi networks (on your device)
public String getCurrentSsid(Context context) { String ssid = null; ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo.isConnected()) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null && !(connectionInfo.getSSID().equals(""))) { //if (connectionInfo != null && !StringUtil.isBlank(connectionInfo.getSSID())) { ssid = connectionInfo.getSSID(); } // Get WiFi status MARAKANA WifiInfo info = wifiManager.getConnectionInfo(); String textStatus = ""; textStatus += "\n\nWiFi Status: " + info.toString(); String BSSID = info.getBSSID(); String MAC = info.getMacAddress(); List<ScanResult> results = wifiManager.getScanResults(); ScanResult bestSignal = null; int count = 1; String etWifiList = ""; for (ScanResult result : results) { etWifiList += count++ + ". " + result.SSID + " : " + result.level + "\n" + result.BSSID + "\n" + result.capabilities +"\n" + "\n=======================\n"; } Log.v(TAG, "from SO: \n"+etWifiList); // List stored networks List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); for (WifiConfiguration config : configs) { textStatus+= "\n\n" + config.toString(); } Log.v(TAG,"from marakana: \n"+textStatus); } return ssid; }
DISCLAIMER: while this is working code, not pseudo code, its only purpose is to illustrate the methods for data extraction from wifi connections and it should be adapted (and cleaned) before use.

Gowthaman M
- 8,057
- 8
- 35
- 54

tony gil
- 9,424
- 6
- 76
- 100
-
@Mr_and_Mrs_D 1. marakana is marko gargenta, the author of many sample projects. 2. as i said, this is a mix and match, including the sample code you refer to. :) – tony gil Apr 22 '13 at 16:14
-
-
-
6
0
Simple as 2 lines
WifiManager w=(WifiManager)getSystemService(Context.WIFI_SERVICE);
String wifi=w.getConnectionInfo().getSSID();
Remember to put this in your Manifest
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

PYK
- 3,674
- 29
- 17