整理了一下最近用到的杀死进程的方法:
/**
* 杀掉进程
* @param packageName 应用包名
*/
private void stopApp(String packageName)
{
String saCmdFile = "/dev/ttySA";
try
{
BufferedWriter writer = new BufferedWriter(new FileWriter(saCmdFile));
writer.write("SA+SYSTEM=\"busybox killall " + packageName + "\"\r\n");//其实就是在adb shell 中执行了:“busybox killall packageName \”
writer.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
同理,执行其他的命令都可以这样写,例如:
private void doCommand()
{
String saCmdFile = "/dev/ttySA";
try
{
BufferedWriter writer = new BufferedWriter(new FileWriter(saCmdFile));
writer.write("SA+SYSTEM=\"xxx command\"\r\n");
writer.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}