Android系绳 - 获取当前的SSID

时间:2012-06-01 13:09:00

标签: android android-wifi tethering

重复问题 - How to get my wifi hotspot ssid in my current android system 抱歉复制此qustion,但它仍然没有答案。我的手机处于网络共享模式,所以我想知道它的SSID。我怎么能找到这个呢?非常感谢!

2 个答案:

答案 0 :(得分: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即可获取热点名称。建议在之前使用Nullpointer检查;)

答案 1 :(得分:2)

WifiManager mng = (WifiManager)context.getSystemService(Context.WIFI_SERVICE).

String currentSSID = mng.getConnectionInfo().getSSID()
相关问题