×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Hafiz Waleed Hussain
Added: Oct 12, 2013 9:39 AM
Views: 32
  1. // Below is activity
  2.  
  3. // onResume()
  4. IntentFilter filter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION);
  5. registerReceiver(networkReceiver, filter);
  6.  
  7. // onPause
  8. unregisterReceiver(networkReceiver);
  9.  
  10. // Broadcast Receiver
  11.         private BroadcastReceiver networkReceiver = new BroadcastReceiver() {
  12.  
  13.                 @Override
  14.                 public void onReceive(Context context, Intent intent) {
  15.  
  16.                         if (intent.getAction().equals(
  17.                                         WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
  18.  
  19.                                 NetworkInfo netInfo = intent
  20.                                                 .getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
  21.  
  22.                                 if (netInfo.isConnected()) {
  23.  
  24.                                 }
  25.                         }
  26.  
  27.                 }
  28.         };