android模拟返回键

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();

}

你可能感兴趣的:(android)