简体   繁体   English

更新系统广播意图的小部件

[英]Update Widget on System Broadcast Intent

I'm working on an Android widget that will show the current network state (ie 1xRTT, EvDo Rev. A, WiMax, etc.). 我正在使用一个Android小部件,它将显示当前的网络状态(即1xRTT,EvDo Rev. A,WiMax等)。 It may seem like a pointless idea, but for whatever the reason, the Evo doesn't differentiate between 1x & EvDo, it just says 3G for both, which is annoying if you're in a fringe 3G area. 这看起来似乎是没有意义的想法,但是无论出于何种原因,Evo都不会在1x和EvDo之间进行区分,只是对两者都说3G,如果您处于边缘3G区域,这将很烦人。

Anyways, to the point: I have the widget complete and it updates with the current network just fine, but how can I make it update whenever the connection changes? 无论如何,要点是:我已经完成了小部件,并且可以使用当前网络进行更新,但是只要连接发生更改,如何使它更新? I know I can use a BroadcastReceiver to catch the ConnectivityManager.CONNECTIVITY_ACTION intent the system sends on a connection change. 我知道我可以使用BroadcastReceiver来捕获系统在连接更改时发送的ConnectivityManager.CONNECTIVITY_ACTION意图。 How can I update the widget from there? 如何从那里更新小部件?

Or can I use the AppWidgetProvider to catch the intent and then update? 还是可以使用AppWidgetProvider捕获意图然后进行更新?

I know how to catch the intent, I just don't know how to update the widget once I do. 我知道如何捕捉意图,我只是不知道如何更新小部件。

Or can I use the AppWidgetProvider to catch the intent and then update? 还是可以使用AppWidgetProvider捕获意图然后进行更新?

That should work. 那应该工作。 You will need to override onReceive() , look for CONNECTIVITY_ACTION Intents , handle those yourself, and chain to the superclass for the default behavior. 您将需要重写onReceive() ,查找CONNECTIVITY_ACTION Intents ,自己处理,然后链接到超类以获得默认行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM