我有非常简单的代码如下:
@Override
public void onClick(View v)
{
Log.i("MyApp", "Started");
try
{
Process processStart = Runtime.getRuntime().exec("su");
}
catch (IOException e1)
{
e1.printStackTrace();
}
String myStringArray[]= {"getevent","/dev/input/event0"};
String line;
try
{
Process process = Runtime.getRuntime().exec(myStringArray);
InputStreamReader inputstreamreader = new InputStreamReader(process.getInputStream());
BufferedReader bufferedReader = new BufferedReader(inputstreamreader);
bufferedReader.read();
while ((line = bufferedReader.readLine()) != null)
{
Log.i("MyApp", line);
}
InputStreamReader errstreamreader = new InputStreamReader(process.getErrorStream());
BufferedReader errReader = new BufferedReader(errstreamreader);
errReader.read();
while ((line = errReader.readLine()) != null)
{
Log.i("MyApp", line);
}
} catch(java.io.IOException e){
}
Log.i("MyApp", "Finished");
}
});
但我收到此错误:
could not open /dev/input/event0, permission denied
我被要求在手机上授予 root 权限,但在此之前它在 logcat 上有错误。
我也尝试过 processStart.waitFor();
但是它将应用程序挂在那里并且根本不前进。我试过到处寻找原因,但无法让它发挥作用。
我也尝试过使用 ProcessBuilder,但是当我使用它时,getevent 根本不返回任何内容......