通过软件Android的返回键 [英] Android back key by software
问题描述
道兴有人知道我可以模拟pressing软件返回键?我已经看到了一些应用程序,模拟此键和其他一些按键如家和搜索。但由于theese是不是开源的,我试图建立自己的应用程序,它可以管理theese任务。回到家里的例子是很容易的,因为我不得不派只是一个意向。所以...我能做些什么来模拟返回键? :)
Dows anybody know how I can simulate pressing the back key by software? I've seen some applications which simulate this key and a few other keys like home and search. But because theese weren't open source, I tried to build my own application which can manage theese tasks. To go back to home for example is very easy because I had to send just one intent. So... what can I do to simulate the back key? :)
更新:
我已经下载了一个开源的应用程序,它从 http://git.hoopajoo.net/ <具有同样的功能/ A>
I've downloaded an open source application which has the same functions from http://git.hoopajoo.net/
有这就像做了:
Process process = Runtime.getRuntime().exec("su");
OutputStream outputStream = process.getOutputStream();
String cmd = "keycode " + KeyEvent.KEYCODE_BACK;
outputStream.write((cmd + "\n").getBytes("ASCII"));
在什么地方键code的命令从何而来?我没有发现任何所谓的二进制文件在我的Android的根文件系统?!?!
Where does the "keycode" command come from? I could not found any so called binary in my Android rootfs?!?!
推荐答案
Aleadam方法,不要在我的Android 4.1.2的工作。我不知道为什么,但这种变通办法:
Aleadam method don't work on my android 4.1.2. I don't know why, but this workaround works:
public void dispachBackKey() {
dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK));
}
这篇关于通过软件Android的返回键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!