我需要创建一个可以通过编程方式执行强制停止按钮对应用程序执行操作的应用程序.(我正在使用root权限)

我试过这段代码:
private void killApp(){
try {
int pid = getPid(com.XXX);
if(pid != -1){
String command = "kill "+pid;
Log.i("Got PID",pid + "");
try {
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
os.writeBytes(command + "\n");
os.flush();
Log.i("Executed","Kill " + pid);
} catch (IOException e) {
// Handle error
}
} else {
Log.i("Not Found","App Not Found");
}
} catch (Exception e) {
e.printStackTrace(); // Device not rooted!
}
}
private int getPid(String …Run Code Online (Sandbox Code Playgroud)