title: Unable to listen to android wi-fi manager's state?
body: <p>I am having some trouble with BroadCast receiver for checking the Wi-fi state. Could you please help?</p>
  
  <p>This is my manifest file.</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_PHONE_STATE"&gt; &lt;/uses-permission&gt;
  &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"&gt; &lt;/uses-permission&gt;
  &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE"&gt; &lt;/uses-permission&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"&gt; &lt;/uses-permission&gt;
  &lt;application 
          android:icon="@drawable/icon" 
          android:label="@string/app_name"&gt;
      &lt;activity 
          android:name=".MainActivity"
              android:label="@string/app_name"&gt;
      &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
      &lt;/intent-filter&gt;
      &lt;/activity&gt;
             &lt;receiver android:name=".MainActivity"&gt;
  &lt;intent-filter android:name="android.net.wifi.WIFI_STATE_CHANGED"/&gt;
         &lt;/receiver&gt;  
     &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>And this is the MainActivity.java</p>
  
  <pre><code>public class MainActivity extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, -1);
          String msg = null;
          switch (state) {
          case WifiManager.WIFI_STATE_DISABLED:
              msg = "it is disabled";
              break;
          case WifiManager.WIFI_STATE_ENABLED:
              msg = "it is enabled";
              break;
          case WifiManager.WIFI_STATE_DISABLING:
              msg = "it is switching off";
              break;
          case WifiManager.WIFI_STATE_ENABLING:
              msg = "wifi is getting enabled";
              break;
          default:
              msg = "not working properly";
              break;
          }
          if (msg != null) {
              Log.d("************%%%%%%%%wifi state ", "WIFI" + msg);
              Toast.makeText(context, "Wifi state is" + msg, Toast.LENGTH_LONG)
                      .show();
          }
      }
  }
  </code></pre>
  
  <p>I am unsure where am I making my mistake. Any input would be appreciated.<br>
  I am not getting any errors just that the log file doesn't show the required message.</p>