[英]How to uninstall android system app programmatically?
我可以获得安装的应用程序列表(用户和系统应用程序)。 我也可以卸载用户应用程序,但是不能卸载系统应用程序。
有什么方法可以卸载系统应用程序? 如果手机已经扎根,那么以下代码可以工作吗?
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:"+appPackageName.getText().toString()));
context.startActivity(intent);
您可以使用以下命令执行根命令:
runCommand("su");
runCommand("rm /data/system/application.package.apk");
runCommand("rm /data/data/application.package");
//when this doesn´t work try
runCommand("rm -r /data/system/application.package.apk");
runCommand("rm -r /data/data/application.package");
public static void runCommand(String command){
try {
Process chmod = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(chmod.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
chmod.waitFor();
outputString = output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
还有一个不错的库: https : //github.com/Free-Software-for-Android/RootCommands
您需要具有root
访问权限才能删除system
或vendor
应用程序。
$ su
# rm /data/system/application.package.apk
# rm /data/data/application.package
在Rooted Device上尝试...有效
Process reboot = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(reboot.getOutputStream());
os.writeBytes("pm uninstall co.example.demo\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
reboot.waitFor();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.