Android - Kill App from another App (on a rooted device)

人盡茶涼 提交于 2019-12-21 02:53:08

问题


I have a rooted Android device. At one point I launch a secondary application from my primary application like so:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.app.package");
startActivityForResult(intent, 100);

I want to be able to kill this secondary application from the primary application. I am trying the following general procedure:

// At an earlier point in time...
Runtime.getRuntime().exec("su");
// The user grants permission

// ...

// At a later point in time...
Runtime.getRuntime().exec("su am force-stop com.app.package");

Unfortunately, this does not kill the app, with no hint as to why from logcat.

If I try to run the killing command as "am force-stop com.app.package" instead of "su am force-stop com.app.package", logcat says that I don't have permission, even though I got superuser permission from running "su" earlier.


回答1:


Found a solution:

Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());

os.writeBytes("adb shell" + "\n");

os.flush();

os.writeBytes("am force-stop com.xxxxxx" + "\n");

os.flush();


来源:https://stackoverflow.com/questions/37864816/android-kill-app-from-another-app-on-a-rooted-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!