首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android tether -获取最新的SSID

Android tether -获取最新的SSID
EN

Stack Overflow用户
提问于 2012-06-01 21:09:00
回答 2查看 5.4K关注 0票数 3

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

EN

回答 2

Stack Overflow用户

发布于 2013-05-03 15:25:18

现在有点晚了,但我最近设法获得了设备热点的SSID。它正在我的Galaxy Nexus上运行,但还没有进行过太多的测试。

代码语言:javascript
复制
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即可获取热点名称。建议在此之前进行空指针检查;)

票数 3
EN

Stack Overflow用户

发布于 2012-06-01 21:24:38

代码语言:javascript
复制
WifiManager mng = (WifiManager)context.getSystemService(Context.WIFI_SERVICE).

String currentSSID = mng.getConnectionInfo().getSSID()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10850936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档