ROOT - 在没有提示对话框的情况下在后台卸载应用程序
ROOT - Uninstall app in background without prompt dialog
大家好,我有一个基于 Android 7.1.1 的 phone,我想在不提示对话框(返回或卸载确认)的情况下卸载应用程序。我的应用程序具有root权限,它也是一个系统应用程序。我尝试通过 "pm uninstall" 命令使用 shell 命令,但它不起作用:
Runtime.getRuntime().exec("su pm uninstall " + packageName);
我得到了"Magisk/E: Unknown id: pm"。我尝试了许多其他组合,带有 shell 前缀等但没有。 Root 运行良好,在清单文件中我放置了 perm "DELETE_PACKAGES"。如果我通过 PC 执行相同的命令。
如何在没有对话框的情况下卸载应用程序?
您可以使用 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();
}
而不是 Runtime.getRuntime().exec("su pm uninstall " + packageName);
试试 运行 Runtime.getRuntime().exec("su -c 'pm uninstall " + packageName + "'");
在您的代码中您忘记添加 -c
,因此 pm uninstall [...]
被视为 su
命令的参数。
大家好,我有一个基于 Android 7.1.1 的 phone,我想在不提示对话框(返回或卸载确认)的情况下卸载应用程序。我的应用程序具有root权限,它也是一个系统应用程序。我尝试通过 "pm uninstall" 命令使用 shell 命令,但它不起作用:
Runtime.getRuntime().exec("su pm uninstall " + packageName);
我得到了"Magisk/E: Unknown id: pm"。我尝试了许多其他组合,带有 shell 前缀等但没有。 Root 运行良好,在清单文件中我放置了 perm "DELETE_PACKAGES"。如果我通过 PC 执行相同的命令。
如何在没有对话框的情况下卸载应用程序?
您可以使用 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();
}
而不是 Runtime.getRuntime().exec("su pm uninstall " + packageName);
试试 运行 Runtime.getRuntime().exec("su -c 'pm uninstall " + packageName + "'");
在您的代码中您忘记添加 -c
,因此 pm uninstall [...]
被视为 su
命令的参数。