How to intercept connection to a Wifi network most efficiently on Android -
i want perform action when phone connects wifi network. far can see have 2 broadcast intent intercept satisfy this: 1. wifi state changed. 2. connectivity changed.
the problem want intercept wifi connected events. receiver triggered on change wifi, including disconnection, don't care about.i feel waste of cpu time.
are there more specific intents, "wifi connected"? or alternatively, can add intent filter achieve this?
thanks!
you can determine type of network event requesting informations. first, make sure registered intentfilter
on wifimanager.network_state_changed_action
action , bind proper broadcastreceiver
.
then in receiver's onreceive
method, can check if received event networkinfo.state.connected
event :
@override public void onreceive(context context, intent intent) { networkinfo networkinfo = intent.getparcelableextra(wifimanager.extra_network_info); if (networkinfo != null && networkinfo.getstate().equals(networkinfo.state.connected) ) { // whatever want } }
Comments
Post a Comment