android - 如何以编程方式卸载android系统应用程序?

标签 android uninstallation

我可以获得已安装应用程序的列表(包括用户应用程序和系统应用程序)。我也可以卸载用户应用程序,但是无法卸载系统应用程序。

有什么办法可以卸载系统应用吗? 如果手机已经 root,下面的代码是否有效?

Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:"+appPackageName.getText().toString()));
                        context.startActivity(intent); 

最佳答案

你可以执行root命令:

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

关于android - 如何以编程方式卸载android系统应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34398650/

相关文章:

android - 安卓二维码阅读器

Android 将数据从应用程序传递到浏览器

android - SwipeDismissBehavior 动画问题

Android:是否可以使用 AlarmManager 完成所有更新任务

powershell - 使用Powershell卸载exe软件

windows-installer - 在 Vista/Win 7 上卸载链式 msi 时出现错误 1730(需要管理员权限)

android - 我想构建一个默认输入法不是Android键盘的android系统

android - 开始对 package_removed 的 Intent

CMake 支持 "make uninstall"吗?

python - 如果 pip 卸载失败会发生什么?