【问题标题】:Android tether - get current SSIDAndroid系绳 - 获取当前的SSID
【发布时间】:2012-06-06 17:36:21
【问题描述】:

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

【问题讨论】:

    标签: android android-wifi tethering


    【解决方案1】:

    有点晚了,但我最近设法获得了设备热点的 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 即可获取热点名称。建议在此之前检查空指针;)

    【讨论】:

    【解决方案2】:
    WifiManager mng = (WifiManager)context.getSystemService(Context.WIFI_SERVICE).
    
    String currentSSID = mng.getConnectionInfo().getSSID()
    

    【讨论】:

    • 这个答案在重复问题中被描述。当它回答时,它无法获取我的 wifi 热点 ssid!
    • 没有。它返回我的 WiFi 路由器的 SSID。
    • 正是@Nolesh。我们想要 wifi ap 的 ssid 而不是 wifi 路由器。你找到解决办法了吗?
    猜你喜欢
    • 1970-01-01
    • 2014-05-27
    • 2022-06-23
    • 2011-11-27
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 1970-01-01
    相关资源
    最近更新 更多