The keydown documentation states that the keydown will be sent again if it's held down, but if you hold down the media key I don't get any notification at all. Is there a way to detect this? It's actually going to a Google (Now?) Search voice-input - perhaps there's a broadcast indicating that is happening I could receive?
Here's my BroadcastReceiver's receiver:
@Override
public void onReceive(Context context, Intent intent)
{
String intentAction = intent.getAction();
int SoundID = 0;
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction))
{
KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event != null)
{
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN)
{
Log.d("Hi", "MEDIA keydown r" + event.getRepeatCount());
if (event.getRepeatCount() == 1)
DoSomethingMagical();
else if (event.getRepeatCount() == 0)
DoSomethingSpecial();
}
}
}
}
You can react on the long press event by adding the following intent-filter to your AndroidManifest.xml:
<intent-filter>
<action android:name="android.speech.action.WEB_SEARCH"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
Unfortunately this will not be handled in the same way as an action of type android.intent.action.MEDIA_BUTTON (your BroadcastReceiver won't be invoked).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With