Skip to content

Instantly share code, notes, and snippets.

@john990
Created April 25, 2014 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john990/11276004 to your computer and use it in GitHub Desktop.
Save john990/11276004 to your computer and use it in GitHub Desktop.
监听wifi状态(android)
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (null != parcelableExtra) {
NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
if (networkInfo.getState() == State.CONNECTED) {
netManager.start(true);
} else if (networkInfo.getState() == State.DISCONNECTED) {
Const.IS_CONNECTED = false;
netManager.close();
Intent netDis = new Intent(Const.NET_STATE_DISCONNECT);
sendBroadcast(netDis);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment