title: Android - onKeyDown called from within onReceive
body: <p>I am totally new to Android development and Java development so please excuse my idiotic question :)</p>
  
  <p>I want to setup an app that stops the SMS sound when a button is pressed.</p>
  
  <p>So far I was able to setup an SMSReceiver that sees when an SMS is being received and does the actions it's told. Here's the code:</p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.media.AudioManager;
  
  public class SMSReceiver extends BroadcastReceiver {
      @Override
  public void onReceive(Context context, Intent intent) {
      AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
      switch (audioManager.getRingerMode()) {
      case AudioManager.RINGER_MODE_VIBRATE:
          audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
          try {
              Thread.sleep(5000);
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
      break;
      case AudioManager.RINGER_MODE_NORMAL:
          audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
          try {
              Thread.sleep(5000);
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
      break;
      }
    }
  }
  </code></pre>
  
  <p>Now, what I need is to do the actions inside the onReceive only when the volume down button is pressed (or any other button for that matter).</p>
  
  <p>I tried to add an onKeyDown method... but I'm not able to sort it out :(. </p>
  
  <p>Can someone please help?</p>