title: [Android]BroadcastReceiver(Action_headset_plug) not firing
body: <p>I declared a BroadcsastReceiver(Action_headset_plug) in AndroidManifest.xml and defined a  BroadcastHandler.class implement BroadcsastReceiver . I run the apk on the device and the receiver doesn't fire. However , it work correctly when I use registerReceiver() in the Activity. Do I miss something in the AndroidManifest.xml?</p>
  
  <p>This is the AndroidManifest.xml</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="irdc.Earphone_test"
        android:versionCode="1"
        android:versionName="1.0"&gt;
      &lt;uses-sdk android:minSdkVersion="9" /&gt;
  &lt;uses-permission android:name="android.permission.ACTION_HEADSET_PLUG"&gt;&lt;/uses-permission&gt;
      &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
          &lt;receiver  android:enabled="true" android:name="BroadcastHandler"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.ACTION_HEADSET_PLUG"&gt;&lt;/action&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;activity android:name=".Earphone_testActivity"
                    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;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <hr>
  
  <p>This is the receiver code</p>
  
  <pre><code>public class BroadcastHandler extends BroadcastReceiver { 
      @Override 
      public void onReceive(Context context, Intent intent) {    
  
          if(intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)){                    
              String mes;
              int state = intent.getIntExtra("state", 4);
              if(state == 0){    
                  mes ="out";   
              }else if(state == 1){    
                  mes ="in";           
              }else {         
                  mes ="others";
              }
              AlertDialog.Builder builder = new AlertDialog.Builder(context);        
              builder.setTitle("Headset broadcast");       
              builder.setMessage(mes);      
              builder.setPositiveButton("Okey-dokey", new DialogInterface.OnClickListener() {    
                  public void onClick(DialogInterface dialog, int which) {              
                      dialog.dismiss();          
                  }      
              });       
              builder.create().show();
  
          } 
  
      } 
  }
  </code></pre>