如何使用 SUPPLICANT_STATE_CHANGED_ACTION WiFi BroadcastReceiver - android
我想在我的设备连接到 wifi 网络时在屏幕上显示连接过程。 SUPPLICANT_STATE_CHANGED_ACTION 由 WifiManager 提供,但我不知道如何使用它。有人可以帮我吗?
I want to show the connection process on the screen when my device is connecting to the wifi network. SUPPLICANT_STATE_CHANGED_ACTION is provided by WifiManager but i don't know how to use it. Can anyone help me please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确实可以将广播意图用于
SUPPLICANT_STATE_CHANGED_ACTION
:应用程序需要其清单文件中的权限:
然后注册系统广播:
registerReceiver()
需要一个实现BroadcastReceiver
作为其第一个参数的类。在该代码中,您可以通过重写onReceive
方法来对 Wifi 状态更改进行操作。例如,有关可能的 Wifi 状态值,请参阅 http://developer.android .com/reference/android/net/wifi/SupplicantState.html
You can indeed use the broadcasted intents for
SUPPLICANT_STATE_CHANGED_ACTION
:The app needs the permission in its Manifest file:
Then register for the system broadcast:
the
registerReceiver()
needs an instance of a class implementingBroadcastReceiver
as its first argument. In that code you can act on the Wifi state changes by overriding theonReceive
method. For exampleFor the possible Wifi state values, see http://developer.android.com/reference/android/net/wifi/SupplicantState.html
我不知道有什么回调方法可以让您知道 wifi 状态何时发生变化。我使用在后台运行的处理程序轮询信息。
将处理程序添加到您的类中。
通过调用启动它
我使用的代码如下。
I don't know of a callback method that lets you know when the wifi status has changed. I polled the information using a Handler running in the background.
Add the handler to your class.
Start it by calling
The code I used is below.