3

Duplicate question - How to get my wifi hotspot ssid in my current android system Sorry for duplicate this qustion, but it still doesn't have the answer. My mobile in tethering mode, so I want to know SSID of it. How can I find this one? Thanks a lot!

Community
  • 1
  • 1
Nolesh
  • 6,126
  • 11
  • 66
  • 105

2 Answers2

3

It's a bit late but i recently managed to get the SSID of the device's hotspot. It's working on my Galaxy Nexus, but haven't tested it quite much.

public static WifiConfiguration getWifiApConfiguration(final Context ctx) {
    final WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    final Method m = getWifiManagerMethod("getWifiApConfiguration", wifiManager);
    if(m != null) {
        try {
            return (WifiConfiguration) m.invoke(wifiManager);
        } catch(Exception e) {
        }
    }
    return null;
}

private static Method getWifiManagerMethod(final String methodName, final WifiManager wifiManager) {
    final Method[] methods = wifiManager.getClass().getDeclaredMethods();
    for (Method method : methods) {
        if (method.getName().equals(methodName)) {
            return method;
        }
    }
    return null;
}

Just call getWifiApConfiguration(getActivity()).SSID to get the hotspot name. Nullpointer check is recommended before ;)

Daniel Amerbauer
  • 553
  • 1
  • 4
  • 8
  • After Android O, this code require specific permission (source :https://stackoverflow.com/a/15121282/4965913). Anybody know how to make this code works after Android O please ? – Maxime Esprit Aug 31 '20 at 14:33
  • I found this to get some information : https://stackoverflow.com/a/45996578/4965913 – Maxime Esprit Aug 31 '20 at 15:08
2
WifiManager mng = (WifiManager)context.getSystemService(Context.WIFI_SERVICE).

String currentSSID = mng.getConnectionInfo().getSSID()
VinceFR
  • 2,415
  • 1
  • 18
  • 27