Android tether - 获取当前的 SSID

标签 android android-wifi tethering

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

最佳答案

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

关于Android tether - 获取当前的 SSID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10850936/

相关文章:

android - 如何通过 wifi 和移动网络 Android 单独获取数据使用?

android - 为什么这个 WifiInfo 有时在 android 上为 null?

android - 以编程方式获取wifi/移动网络的数据速度

macos - 用于 USB 系绳和 WiFi 的 OSX 链接聚合?

java - 如何修复 'android.os.NetworkOnMainThreadException' ?

android - 如何仅加载当前在屏幕上可见的标记(Android 上的 Google map )

android - 如何在 android 中为布局生成唯一 ID?

java - 使用 jsoup 收集倒数计时器并为 android 设置一个计时器

android - android 设备上的强制门户

android - 在 Android-x86 上网本上使用 ADB over Bluetooth 调试应用程序