【问题标题】:get the ssid and the password of the hotspot android 8.0 and higher获取热点android 8.0及更高版本的ssid和密码
【发布时间】:2025-12-24 13:00:11
【问题描述】:

您好,我尝试获取热点的 ssid 和密码。我在下面的方法中使用,它对 android 的工作低于 8。 但在 android 8.0 它的 throw exption 中,我读到我需要获得一些 premisiion 权限:android.permission.OVERRIDE_WIFI_CONFIG。 但我们不能得到这个前提

   Method[] methods = m_wifiManager.getClass().getDeclaredMethods();
    for (Method m : methods) {
        if (m.getName().equals("getWifiApConfiguration")) {
            try {
                m_wifiConf = (WifiConfiguration) m.invoke(m_wifiManager);
                message = m_wifiConf.SSID + '/' + m_wifiConf.preSharedKey + '/';
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }

        }

【问题讨论】:

    标签: android passwords hotspot ssid


    【解决方案1】:

    不确定这是否与您的反射方法有关,但从 Android 8.1 开始,您至少需要启用ACCESS_COARSE_LOCATION 权限和位置服务才能使用getConnectionInfo()(请参阅getScanResults())。

    无论如何,这不会让您访问 wifi 密码。

    OVERRIDE_WIFI_CONFIG权限为defined as

    <permission android:name="android.permission.OVERRIDE_WIFI_CONFIG"
    android:protectionLevel="signature|privileged" />
    

    这意味着您的应用必须由平台密钥签名或添加到特权whitelist 才能使用此权限。

    【讨论】: