本文整理了Java中android.app.Instrumentation.sendKeyDownUpSync()
方法的一些代码示例,展示了Instrumentation.sendKeyDownUpSync()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instrumentation.sendKeyDownUpSync()
方法的具体详情如下:
包路径:android.app.Instrumentation
类名称:Instrumentation
方法名:sendKeyDownUpSync
暂无
代码示例来源:origin: android-hacker/VirtualXposed
@Override
public void sendKeyDownUpSync(int key) {
base.sendKeyDownUpSync(key);
}
代码示例来源:origin: RobotiumTech/robotium
/**
* Sends the back button command a given number of times
*
* @param numberOfTimes the number of times to press "back"
*/
private void useGoBack(int numberOfTimes){
for(int i = 0; i < numberOfTimes; i++){
try {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
sleeper.sleep(MINISLEEP);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
} catch (Throwable ignored) {
// Guard against lack of INJECT_EVENT permission
}
}
}
代码示例来源:origin: stackoverflow.com
new Thread(new Runnable() {
@Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
for ( int i = 0; i < 10; ++i ) {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
Thread.sleep(2000);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
Thread.sleep(2000);
}
}
catch(InterruptedException e){
}
}
}).start();
代码示例来源:origin: RobotiumTech/robotium
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
dialogUtils.waitForDialogToOpen(Timeout.getSmallTimeout(), true);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
}catch(SecurityException e){
Assert.fail("Can not press the menu!");
for (int i = 0; i < index; i++) {
sleeper.sleepMini();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER);
}catch (SecurityException ignored) {}
代码示例来源:origin: RobotiumTech/robotium
/**
* Simulates pressing the hardware back key.
*/
public void goBack() {
sleeper.sleep();
try {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
sleeper.sleep();
} catch (Throwable ignored) {}
}
}
代码示例来源:origin: RobotiumTech/robotium
/**
* Long clicks on a specific {@link TextView} and then selects
* an item from the context menu that appears. Will automatically scroll when needed.
*
* @param text the text that should be clicked on. The parameter <strong>will</strong> be interpreted as a regular expression.
* @param index the index of the menu item that should be pressed
*/
public void clickLongOnTextAndPress(String text, int index)
{
clickOnText(text, true, 0, true, 0);
dialogUtils.waitForDialogToOpen(Timeout.getSmallTimeout(), true);
try{
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
}catch(SecurityException e){
Assert.fail("Can not press the context menu!");
}
for(int i = 0; i < index; i++)
{
sleeper.sleepMini();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
}
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER);
}
代码示例来源:origin: RobotiumTech/robotium
/**
* Returns to the given {@link Activity}.
*
* @param name the name of the {@code Activity} to return to, e.g. {@code "MyActivity"}
*/
public void goBackToActivity(String name)
{
ArrayList<Activity> activitiesOpened = getAllOpenedActivities();
boolean found = false;
for(int i = 0; i < activitiesOpened.size(); i++){
if(activitiesOpened.get(i).getClass().getSimpleName().equals(name)){
found = true;
break;
}
}
if(found){
while(!getCurrentActivity().getClass().getSimpleName().equals(name))
{
try{
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
}catch(SecurityException ignored){}
}
}
else{
for (int i = 0; i < activitiesOpened.size(); i++){
Log.d(LOG_TAG, "Activity priorly opened: "+ activitiesOpened.get(i).getClass().getSimpleName());
}
Assert.fail("No Activity named: '" + name + "' has been priorly opened");
}
}
代码示例来源:origin: RobotiumTech/robotium
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
}catch(SecurityException ignored){}
if(countingUp){
try{
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
}catch(SecurityException ignored){}
}else{
try{
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
}catch(SecurityException ignored){}
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER);
}catch(SecurityException ignored){}
代码示例来源:origin: EggUncle/XposedNavigationBar
@Override
protected void startOrPauseMusic() {
if (isPlaying) {
mInst.sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_PAUSE);
isPlaying = false;
} else {
mInst.sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_PLAY);
isPlaying = true;
}
}
代码示例来源:origin: EggUncle/XposedNavigationBar
@Override
protected void previousMusic() {
mInst.sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_PREVIOUS);
}
}
代码示例来源:origin: stackoverflow.com
Instrumentation inst = new Instrumentation();
for ( int i = 0; i < 10; ++i ) {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
Thread.sleep(2000);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
Thread.sleep(2000);
}
代码示例来源:origin: andyiac/githot
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(keyCode);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
代码示例来源:origin: stackoverflow.com
new Thread(new Runnable() {
@Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
//This is for Volume Down, change to
//KEYCODE_VOLUME_UP for Volume Up.
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_DOWN);
}catch(InterruptedException e){}
}
}).start();
代码示例来源:origin: Shimingli/WritingPen
@Override
public void run() {
try {
// 创建一个Instrumentation对象
Instrumentation inst = new Instrumentation();
// 调用inst对象的按键模拟方法
inst.sendKeyDownUpSync(keyCode);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
代码示例来源:origin: mttkay/calculon
public void run() {
for (int code : keyCodes) {
instrumentation.sendKeyDownUpSync(code);
}
instrumentation.waitForIdleSync();
}
}, false);
代码示例来源:origin: luili16/UIMocker
@Override
@CallSuper
public void sendKeyDownUpSync(int key) {
if (DEBUG) {
Logger.d(TAG,"sendKeyDownUpSync");
}
mInstrumentation.sendKeyDownUpSync(key);
}
代码示例来源:origin: stackoverflow.com
final Instrumentation i = new Instrumentation();
Thread t = new Thread(){
public void run(){
i.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
}
};
t.start();
代码示例来源:origin: com.jayway.android.robotium/robotium-solo
/**
* Simulates pressing the hardware back key.
*/
public void goBack() {
sleeper.sleep();
try {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
sleeper.sleep();
} catch (Throwable ignored) {}
}
}
代码示例来源:origin: stackoverflow.com
public void testSearch() {
Instrumentation instrumentation = getInstrumentation();
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_SEARCH);
instrumentation.sendCharacterSync(KeyEvent.KEYCODE_F);
instrumentation.sendCharacterSync(KeyEvent.KEYCODE_O);
instrumentation.sendCharacterSync(KeyEvent.KEYCODE_O);
//Assert here for whatever you want.
}
代码示例来源:origin: com.jayway.android.robotium/robotium-core
/**
* Simulates pressing the hardware back key.
*
*/
public void goBack() {
sleeper.sleep();
inst.waitForIdleSync();
try {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
sleeper.sleep();
} catch (Throwable e) {}
}
内容来源于网络,如有侵权,请联系作者删除!