title: BroadcastReceiver for unplug of headphone
body: <p>Hi i am working on an application that generate an event when ever the headphone is removed from the mobile phone.
  I have created a broadcast receiver with receive method as</p>
  
  <pre><code>public void onReceive(Context context, Intent intent) {
  
          // TODO Auto-generated method stub
          String action = intent.getAction();
          Log.i("Broadcast Receiver", "Hello");
          if( (action.compareTo(Intent.ACTION_HEADSET_PLUG))  == 0)   //if the action match a headset one
          {
              int headSetState = intent.getIntExtra("state", 0);      //get the headset state property
              int hasMicrophone = intent.getIntExtra("microphone", 0);//get the headset microphone property
              if( (headSetState == 0) &amp;&amp; (hasMicrophone == 0))        //headset was unplugged &amp; has no microphone
              {
  
                      //do whatever
              }
          }           
  
      }
  </code></pre>
  
  <p>Calling this method as follows</p>
  
  <pre><code> IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
          HeadSetBroadCastReceiver receiver = new HeadSetBroadCastReceiver();
          registerReceiver( receiver, receiverFilter );
  </code></pre>
  
  <p>also i have register this in manifest as</p>
  
  <pre><code>   &lt;receiver android:name=".HeadsetBroadCastReceiver"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.ACTION_HEADSET_PLUG"/&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>and permission
  </p>
  
  <p>But this doesnot works can anyone guide me through this?</p>