I am developing an Android apps where user is able to find the phone once it is lost and I plan to implement the remote ringing function, I would like to do something like when the alarm is ringing, no matter the volume up or down key is pressed, the volume will still remain loudest while the alarm is ringing… But I have no idea how to achieve this… I just able to detect the event of volume keys pressed… Kindly need help for this.. Thanks…
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
Toast.makeText(this, "Volume Up", Toast.LENGTH_LONG).show();
return true;
}
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
Toast.makeText(this, "Volume Down", Toast.LENGTH_LONG).show();
return true;
}
return super.onKeyDown(keyCode, event);
}
Your code works fine for me. I threw it into a basic app, and it successfully intercepted the key presses without changing the volume on my device.
Have you tried overriding
onKeyUpas well asonKeyDown?EDIT: Note that this does not work in Services. You simply cannot intercept hardware volume button presses in services.