title: Why is my BroadCast Receiver not working?
body: <p>I am learning about BroadCast Receivers. What I am trying to achieve with the following piece of code is, I would like to see a toast when I switch to airplane mode, where the app is on or not. What am I not doing / Doing wrong? Please Help. Thanks</p>
  
  <p>ConnectivityChangedReceiver.java class</p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.net.ConnectivityManager;
  import android.net.NetworkInfo;
  import android.widget.Toast;
  
  public class ConnectivityChangedReceiver extends BroadcastReceiver {
  
  @Override
  public void onReceive( Context context, Intent intent )
  {
      Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
  
  }
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_PHONE_STATE"&gt;&lt;/uses-permission&gt;
  &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
  &lt;uses-permission android:name="android.permission.SEND_SMS"/&gt;
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&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=".ConnectivityChangedReceiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.AIRPLANE_MODE"&gt;
              &lt;/action&gt;
          &lt;/intent-filter&gt;
  
      &lt;/receiver&gt;
  
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>MainActivity.java`</p>
  
  <pre><code> import android.support.v7.app.AppCompatActivity;
   import android.os.Bundle;
   import android.content.Intent;
  
  
   import java.util.ArrayList;
  
   public class MainActivity extends AppCompatActivity {
  
  private TextView switchStatus;
  private Switch mySwitch;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
   }
   }
  </code></pre>