ROOT - 在没有提示对话框的情况下在后台卸载app

时间:2017-11-28 09:57:53

标签: android root uninstall

大家好我有一个基于Android 7.1.1的root手机,我想要卸载应用程序而不提示对话框(返回或卸载确认)。我的应用程序具有root权限,它也是一个系统应用程序。我试过通过" pm uninstall"使用shell命令。命令,但它不起作用:

Runtime.getRuntime().exec("su pm uninstall " + packageName);

我得到了" Magisk / E:未知身份:下午"。我尝试了许多其他组合,使用shell前缀等但没有。 Root工作得很好,在清单文件中我把perm" DELETE_PACKAGES"。如果我通过PC执行相同的命令。

如何在没有对话框的情况下卸载应用程序?

2 个答案:

答案 0 :(得分:1)

而不是Runtime.getRuntime().exec("su pm uninstall " + packageName);尝试运行Runtime.getRuntime().exec("su -c 'pm uninstall " + packageName + "'");

在您的代码中,您忘记添加-c,因此pm uninstall [...]被视为su命令的参数。

答案 1 :(得分:0)

您可以使用DataOutputStream尝试此操作:

        try
        {
            Process p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            os.writeBytes("pm uninstall " + packageName + "\n");
            os.writeBytes("exit\n");
            os.flush();

            p.waitFor();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        } catch (InterruptedException e)
        {
            e.printStackTrace();
        }