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
Android Emulator: How to Monitor Network Traffic
Returning from an Activity Using Navigateupfromsametask()
Getapplicationcontext(), Getbasecontext(), Getapplication(), Getparent()
Gradle Error: Minimum Supported Gradle Version Is 3.3. Current Version Is 3.2
How to Fix Error: No Signature of Method: Build_Ap86Oam3Dut3Pxce3X49Rdtma.Android()
Supporting Multiple Screen Size - Android
Full Screen Background Image in an Activity
How to Receive Serial Data Using Android Bluetooth
How to Show Android Checkbox at Right Side
What Is the Purpose of "Android.Intent.Category.Default"
How to Check Edittext's Text Is Email Address or Not
Slide a Layout Up from Bottom of Screen
Android Volley + JSONobjectrequest Caching
How to Use View Pager with Views (Not with Fragments)
Comparing Bitmap Images in Android