Yes, there’s a way. You need a class called Wifiinfo
Add these permissions to the manifest
:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
And the code specifically, without using a broadcast:
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo;
String ssid = null;
wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo.getSupplicantState() == SupplicantState.COMPLETED) {
ssid = wifiInfo.getSSID();
}
- From Android 8.1 (API 27), you also need to add this permission to
manifest
, if you are working with this API:
ACCESS_COARSE_LOCATION
or ACCESS_FINE_LOCATION
Source: https://stackoverflow.com/questions/21391395/get-ssid-when-wifi-is-connected