监听遥控器的左键和右键,当连续按下左左右右后,弹出Toast
private long liftTime = 0;private long rightTime = 0;int leftCount = 0;int rightCount = 0;@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode==KeyEvent.KEYCODE_DPAD_LEFT && event.getAction() == KeyEvent.ACTION_DOWN){leftCount++;liftTime = System.currentTimeMillis();}else if (keyCode==KeyEvent.KEYCODE_DPAD_RIGHT && event.getAction() == KeyEvent.ACTION_DOWN){rightCount++;rightTime = System.currentTimeMillis();}Log.e("TAG","rightTime-liftTime = "+(rightTime-liftTime));Log.e("TAG","leftCount = "+leftCount);Log.e("TAG","rightCount"+rightCount);if (rightTime-liftTime < 2000 && leftCount == 2 && rightCount == 2){leftCount = 0;rightCount = 0;Toast.makeText(this,"退出应用", Toast.LENGTH_SHORT).show();}return super.onKeyDown(keyCode, event);}