Skip to content

Instantly share code, notes, and snippets.

@XinyueZ
Created July 31, 2014 19:38
Show Gist options
  • Save XinyueZ/2dbe5a14a7d445fd5878 to your computer and use it in GitHub Desktop.
Save XinyueZ/2dbe5a14a7d445fd5878 to your computer and use it in GitHub Desktop.
Wifi Changed Receiver, based on Otto-Bus.
/*
<receiver android:name=".WifiNetworkChangedReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>
*/
/**
* Receiver to detect status of Wifi.
*/
public final class WifiNetworkChangedReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if(info!=null && TextUtils.equals(info.getTypeName(), "WIFI")) {
BusProvider.getBus().post(new WifiEvent(info.isConnected()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment