title: Capture Voice Dialer or Call Button from Bluetooth Headset
body: <p>I recently bought a Bluetooth headset, <a href="http://www.plantronics.com/middle-east/product/ml20" rel="nofollow">http://www.plantronics.com/middle-east/product/ml20</a>, and have been attempting to receive the call button press to trigger a RecognizerIntent.  However so far all my attempts have failed.  Thinking that perhaps my headset was quirky and didn't operate as expected, I attempting to intercept whatever action triggered the Voice Dialer on my phone from the headset's long press, again resulting in failure.  Below is the code I'm using, which according to all of the other threads I've read should be working.  Am I missing something?  Is ACTION_VOICE_COMMAND not what triggers the voice dialer?</p>
  
  <pre><code>private MediaButtonIntentReceiver receiver = new MediaButtonIntentReceiver();
  private IntentFilter filter1 = new IntentFilter(Intent.ACTION_VOICE_COMMAND);
  private IntentFilter filter2 = new IntentFilter(Intent.ACTION_CALL_BUTTON);
  private IntentFilter filter3 = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
  private IntentFilter filter4 = new IntentFilter(Intent.ACTION_POWER_DISCONNECTED);
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      speech_text = (EditText) findViewById(R.id.voiceInput);
  
      filter1.setPriority(100000);
      filter2.setPriority(100000);
      filter3.setPriority(100000);
      filter4.setPriority(100000);
  
      this.registerReceiver(receiver, filter1);
      this.registerReceiver(receiver, filter2);
      this.registerReceiver(receiver, filter3);
      this.registerReceiver(receiver, filter4);
  }
  
  
  public class MediaButtonIntentReceiver extends BroadcastReceiver {
  
  public MediaButtonIntentReceiver() {
      super();
  }
  
  @Override
  public void onReceive(Context context, Intent intent) {
      /*String intentAction = intent.getAction();
      if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
          return;
      }
      KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
      if (event == null) {
          return;
      }
      int action = event.getAction();
      if (action == KeyEvent.ACTION_DOWN) {
          // do something*/
          Toast.makeText(context, "BUTTON PRESSED!", Toast.LENGTH_LONG).show(); 
          Log.v("TEST", "I am logging something informational!"); 
      //}
      //abortBroadcast();
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.BLUETOOTH"/&gt;
  &lt;uses-permission android:name="android.permission.BROADCAST_STICKY" /&gt;
  &lt;uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /&gt;  
  </code></pre>
  
  <p>Some example output from logcat</p>
  
  <pre><code>01-17 18:36:03.977: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:04.977: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:05.477: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:05.978: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:06.477: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:10.967: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:11.768: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:12.608: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:13.238: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:13.948: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:14.618: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  01-17 18:36:15.278: E/bt-rfcomm(6240): PORT_DataInd, p_port:0x6a90b668, p_data_co_callback is null
  </code></pre>