Created
July 31, 2014 19:38
-
-
Save XinyueZ/2dbe5a14a7d445fd5878 to your computer and use it in GitHub Desktop.
Wifi Changed Receiver, based on Otto-Bus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<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