首页 > 解决方案 > 列出 Android Q / API 29 上的 WiFi 网络

问题描述

我目前正在将我的应用程序迁移到 Android Q。我想列出所有已配置的 WiFi 网络,并且在 QI 能够使用WiFiManager 中的函数getConfiguredNetworks之前列出。遗憾的是,此方法在 API 级别 29 上已弃用,并在 Android Q 设备上返回一个空列表。

弃用评论仅指我也想连接到这些网络的情况。我不想这样做,我只想列出网络及其名称并获取它们的 internal id。你有什么想法我应该如何在 Q 中做到这一点?

标签: androidandroid-wifiandroid-10.0

解决方案


我想没有办法在 Android Q 及更高版本中获得配置的 WiFi 网络。唯一的方法是获取当前可用的网络,getScanResults()我知道这实际上并不能解决获取配置的网络名称的问题。而是只获取当前可用的网络。

    List<ScanResult> results = null;
    TextView outputs = (TextView)findViewById(R.id.outputs);
    try{
        WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
        results = wifiManager.getScanResults();
        int len = results.size();
        String res = null;
        for (int i = 0; i < len; i++) {
            res = outputs.getText() + "\n" + results.get(i).SSID;
            outputs.setText(res);

        }

    }
    catch(Exception e)
    {
        Log.e("MainActivity",e.getMessage());
    }

目前,他们仅根据其文档提供触发与 WiFi 网络连接的机制。让我们希望有什么事情发生或不发生


推荐阅读