24
|
You can register a
BroadcastReceiver to be notified when a WiFi connection is established (or if the connection changed).
Register the
BroadcastReceiver :
And then in your
BroadcastReceiver do something like this:
For more info, see the documentation for
BroadcastReceiver and WifiManager
Of course you should check whether the device is already connected to WiFi before this.
---------------------------------------------------------------------------------------------------------------
IntentFilter filter = new IntentFilter(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
br r = new br();
registerReceiver(r,filter);
=======================================================================
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) {
//do stuff
Toast.makeText(context, "wifi on",Toast.LENGTH_SHORT).show();
} else {
// wifi connection was lost
Toast.makeText(context, "wifi off",Toast.LENGTH_SHORT).show();
}
}
}
|
2013年3月5日 星期二
WIFI BroadcastReceiver Detect
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言