2

How do apps like tasker capture context. Suppose I want to capture context that when wifi is switched on do something. Is it possible to attach a callback for isWifiEnabled()? or execute a handler when wifi gets enabled without polling. An example code or link to an example code to perform some action when wifi is enabled would be nice. There is isWifiEnabled() function in the api but I am not sure how to use this using Intents.

4

1 回答 1

2

当这些事件发生时,他们正在收听广播的系统消息。

https://developer.android.com/guide/components/intents-filters.html

当 WiFi 打开或关闭时,会广播一个 Intent,其操作设置为WIFI_STATE_CHANGED_ACTION。如果您创建了<receiver>一个<intent-filter>集合来捕获它,您的应用程序将收到通知。

于 2013-02-26T16:14:32.900 回答