I thought this was disabled at the OS level....otherwise wouldn't we be able to press to start a dialing app on our BT Headsets?
On Apr 29, 1:31 am, mort <[email protected]> wrote: > Hi, > > it's pretty simple: add a broadcast listener to MEDIA_BUTTON: > <intent-filter android:priority="<some number>"> > <action android:name="android.intent.action.MEDIA_BUTTON" /> > </intent-filter> > > You need to give it a "priority", which decides whether it's handled > before or after other apps. In other words, it's pure coincidence who > picked the highest number... > If you handled the button press, you should abort the broadcast with > abortBroadcast(). Trouble with this handling is, the priorities and > abortBroadcast() work fine as long as each app only responds while > e.g. something is played. But several users also expect a "default > player" to be launched (or start playing) upon button press, like the > default player, so it might happen some app with a higher priority > number won't let the intent come through to your app... (I already > filed an issue to improve > that:http://code.google.com/p/android/issues/detail?id=7772 > - no response so far...) > > In the onReceive, you can get the button event with > KeyEvent key = (KeyEvent) > intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); > > key.getKeyAction() tells you whether the button was released or > pressed, key.getKeyCode() tells which button. The values are > documented and pretty self explaining, like KeyEvent.ACTION_DOWN or > KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE. > Regarding press and release, keep in mind several headsets do own > processing which prevents this (like e.g. closing the connection or > sending "stop" on long press on play/pause) or simply send both at > once when the key is pressed or released. Also, some BT drivers are a > bit unreliable in that regard... > > If you want to handle single button cable headsets as well, also > regard the key code KEYCODE_HEADSETHOOK. > > btw: HTC Hero doesn't implement this standard, it needs a workaround > app. > > HTH, > Mirko > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group > athttp://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

