在 Android 10 上以编程方式断开 Wifi [英] Disconnect Wifi programmatically on Android 10

查看:92
本文介绍了在 Android 10 上以编程方式断开 Wifi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WifiNetworkSuggestion 以编程方式将我的应用程序连接到我的热点,但是当我尝试以编程方式断开此连接时,我使用了 removeNetworkSuggestions 就像文档提到的那样

I use WifiNetworkSuggestion to connect programmatically my app to my hotspot, but when I tried to disconnect from this connection programmatically I used removeNetworkSuggestions like the doc mention

删除部分或全部以前的网络建议由应用程序提供.如果使用了被删除的建议之一建立与当前网络的连接,然后设备将立即断开与该网络的连接.

Remove some or all of the network suggestions that were previously provided by the app. If one of the suggestions being removed was used to establish connection to the current network, then the device will immediately disconnect from that network.

我发现这是一个错误 https://issuetracker.google.com/issues/140398818,所以我的问题是:现在无法在 Android 10 上以编程方式与 wifi 断开连接 ??

I found that it's a bug https://issuetracker.google.com/issues/140398818, so my question is : there's no way right now to disconnect from a wifi programmatically on Android 10 ??

谢谢

推荐答案

Android 10+ 中的 >Settings.Panel,您可以在其中显示弹出 Intent 以提示用户快速更改 Wifi、NFC 等设置,而无需打开设置菜单.

There is Settings.Panel in Android 10+, where you can show popup intents to prompt user to change settings like Wifi, NFC etc. quickly without opening up the settings menu.

您可以简单地显示 WiFi 弹出窗口,如下所示.

You can simply show the WiFi popup as follows.

startActivityForResult(Intent(Settings.Panel.ACTION_WIFI), ENABLE_WIFI_REQUEST)

从这里,用户可以切换 WiFi 以及连接到不同的网络,而无需离开应用程序.

From here, user can toggle WiFi as well as connect to a different network without having to leave the app.

这篇关于在 Android 10 上以编程方式断开 Wifi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆