📜  检测电视遥控键 andoid studio - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:28.556000             🧑  作者: Mango

代码示例1
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.d("debug", "we are here");
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_DPAD_RIGHT:
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_ESCAPE:
            Log.d("OnKey", "key pressed!");
            Toast.makeText(MainActivity.this, "key pressed!", Toast.LENGTH_SHORT).show();
            return true;
    }
    return false;
}