android - 列出 Android Q / API 29 上的 WiFi 网络
问题描述
我目前正在将我的应用程序迁移到 Android Q。我想列出所有已配置的 WiFi 网络,并且在 QI 能够使用WiFiManager 中的函数getConfiguredNetworks之前列出。遗憾的是,此方法在 API 级别 29 上已弃用,并在 Android Q 设备上返回一个空列表。
弃用评论仅指我也想连接到这些网络的情况。我不想这样做,我只想列出网络及其名称并获取它们的 internal id
。你有什么想法我应该如何在 Q 中做到这一点?
解决方案
我想没有办法在 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 网络连接的机制。让我们希望有什么事情发生或不发生
推荐阅读
- angular - 构造函数中的服务与组件中列为提供者的区别?
- html - Angular 7 动画 - 过渡不起作用
- javascript - 错误反应本机运行窗口“无法获取未定义或空引用的属性'方向'”
- sql - 如何使用 hive 从给定范围生成随机日期
- python - 观察dataframe中某列的行数据,看值是否一一变化
- google-kubernetes-engine - IAP 配置后无法访问 GKE 上的 Spinnaker
- python - 使用 pip 安装应用程序而不是包
- c++ - C++ 程序在调用 free() 时崩溃
- c - 为什么这个数组中的值不足?
- php - HTML 自定义按钮