android模拟返回键
16lz
2022-01-27
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中view组件使用详解
- android 隐藏状态栏和导航栏
- android如何调用Web Service手机归属地练习
- android获取控件的几种方法
- Android代码混淆官方实现方法
- Android(安卓)获取手机屏幕大小两种方法
- android开关按钮,Switch,ToggleButton,RadioButton,CheckBox ,多种实
- 浅谈Java中Collections.sort对List排序的两种方法
- Python list sort方法的具体使用