android模拟返回键
16lz
2021-01-23
public void testClick(View v){
/**
* 方法1
*/
new Thread(){
public void run() {
Instrumentation in=new Instrumentation();
in.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
};
}.start();
/**
* 方法2
*/
new Thread(){
public void run() {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("input keyevent " + KeyEvent.KEYCODE_BACK);
} catch (IOException e) {
e.printStackTrace();
}
};
}.start();
}
/**
* 方法1
*/
new Thread(){
public void run() {
Instrumentation in=new Instrumentation();
in.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
};
}.start();
/**
* 方法2
*/
new Thread(){
public void run() {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("input keyevent " + KeyEvent.KEYCODE_BACK);
} catch (IOException e) {
e.printStackTrace();
}
};
}.start();
}
更多相关文章
- android获取控件的几种方法
- Android 获取手机屏幕大小两种方法
- Android Timer 实现方法
- Android 显示/隐藏 软键盘 方法
- Android中的一些方法-----生生不息
- android 模拟器 PANIC: Could not open: AVD 解决方法
- Android里面WebView加载HTML里面点击按钮调我Android方法