Используйте это в своей деятельности
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN)
{
//your code
return false;
}
if(keyCode==KeyEvent.KEYCODE_DPAD_CENTER)
{
/*yourcode*/
return false;
}
if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT)
{
//your code
return false;
}
if(keyCode==KeyEvent.KEYCODE_DPAD_RIGHT)
{
//your code
return false;
}
if(keyCode==KeyEvent.KEYCODE_DPAD_UP)
{
//your code
return false;
}
return super.onKeyDown(keyCode, event);
}
Отредактированный код
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KeyEvent.KEYCODE_DPAD_CENTER)
{
Toast.makeText(<Activity_name>.this, "Application Quits", Toast.LENGTH_SHORT).show();
finish();
return false;
}
return super.onKeyDown(keyCode, event);
}