How to Get Name of Wifi-Network Out of Android Using Android API

How to get name of wifi-network out of android using android API?

android.net.wifi.WifiInfo.getSSID?



WifiManager wifiMgr = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
String name = wifiInfo.getSSID();

How to get current wifi connection name in android pie(9) devices?

This is related to permissions....since API level 27 you need either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission. You may also need CHANGE_WIFI_STATE for Android 9 (that's the case for wifi scan anyway as per google permisson model

then try this code

   ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
wifiInfo.getSSID();
String name = networkInfo.getExtraInfo();
String ssid = "\"" + wifiInfo.getSSID() + "\"";
}

Get SSID when WIFI is connected

I listen for WifiManager.NETWORK_STATE_CHANGED_ACTION in a broadcast receiver

if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
NetworkInfo netInfo = intent.getParcelableExtra (WifiManager.EXTRA_NETWORK_INFO);
if (ConnectivityManager.TYPE_WIFI == netInfo.getType ()) {
...
}
}

I check for netInfo.isConnected(). Then I am able to use

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo();
String ssid = info.getSSID();

UPDATE

From android 8.0 onwards we wont be getting SSID of the connected network unless location services are enabled and your app has the permission to access it.

How to get the name of the connected network in android?

You can use this:

android.net.wifi.WifiInfo.getSSID

Please refer:

How to get name of wifi-network out of android using android API?

How to get the name of currently connected WiFi network in Android with BroadcastReceiver

Get Wifi Interface name on Android

Try this

for(Enumeration<NetworkInterface> list = NetworkInterface.getNetworkInterfaces(); list.hasMoreElements();)
{
NetworkInterface i = list.nextElement();
Log.e("network_interfaces", "display name " + i.getDisplayName());
}


Related Topics



Leave a reply



Submit