3

重复问题 -如何在我当前的 android 系统中获取我的 wifi 热点 ssid 抱歉重复了这个问题,但它仍然没有答案。我的手机处于网络共享模式,所以我想知道它的 SSID。我怎样才能找到这个?非常感谢!

4

2 回答 2

3

有点晚了,但我最近设法获得了设备热点的 SSID。它可以在我的 Galaxy Nexus 上运行,但尚未对其进行太多测试。

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;
}

只需调用 getWifiApConfiguration(getActivity()).SSID 即可获取热点名称。建议在此之前检查空指针;)

于 2013-05-03T07:25:18.427 回答
2
WifiManager mng = (WifiManager)context.getSystemService(Context.WIFI_SERVICE).

String currentSSID = mng.getConnectionInfo().getSSID()
于 2012-06-01T13:24:38.260 回答