I wanted to create a broadcastreceiver which listens for android.intent.action.MEDIA_BUTTON, and get the extra_key_event from that and act accordingly. Somehow the onreceive action is not performed.
In my Manifest:
receiver android:name="MediaButtonReceiver"
intent-filter
action android:name="android.intent.action.MEDIA_BUTTON"
intent-filter
receiver
In my broadcastreceiver:
public class MVCS extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
/* handle media button intent here by reading contents */
/* of EXTRA_KEY_EVENT to know which key was pressed */
KeyEvent ke = (KeyEvent)intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
if (ke .getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
Toast.makeText(context, "BUTTON PRESSED!", Toast.LENGTH_SHORT).show();
}
}
}
However, nothing is displayed when i press the volume down key.
Any help would be much appreciated!