private void sendVolumeKey(int keyCode){
  assertTrue(keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN);
  long down=SystemClock.uptimeMillis();
  KeyEvent keyDown=new KeyEvent(down,down,KeyEvent.ACTION_DOWN,keyCode,0,0);
  mTalkBack.onKeyEventShared(keyDown);
  long up=SystemClock.uptimeMillis();
  KeyEvent keyUp=new KeyEvent(down,up,KeyEvent.ACTION_UP,keyCode,0,0);
  mTalkBack.onKeyEventShared(keyUp);
}

private void sendVolumeKey ( int keyCode ) { assertTrue ( keyCode == KeyEvent . KEYCODE_VOLUME_UP || keyCode == KeyEvent . KEYCODE_VOLUME_DOWN ) ; long down = SystemClock . uptimeMillis ( ) ; KeyEvent keyDown = new KeyEvent ( down , down , KeyEvent . ACTION_DOWN , keyCode , 0 , 0 ) ; mTalkBack . onKeyEventShared ( keyDown ) ; long up = SystemClock . uptimeMillis ( ) ; KeyEvent keyUp = new KeyEvent ( down , up , KeyEvent . ACTION_UP , keyCode , 0 , 0 ) ; mTalkBack . onKeyEventShared ( keyUp ) ; }
volume button simulation needs to be handled separately from key event simulation because the normal android system instrumentation will just change the system volume instead of delivering the volume key events to talkback .
