如何以编程方式卸载android系统应用程序? [英] How to uninstall android system app programmatically?

查看:378
本文介绍了如何以编程方式卸载android系统应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以获得已安装的应用程序列表(用户和系统应用程序).我也可以卸载用户应用程序,但是不能卸载系统应用程序.

I can get a list of installed apps (both user and system apps). I am also able to uninstall user apps, however, not able to uninstall system apps.

有什么方法可以卸载系统应用程序?如果手机已经扎根,以下代码是否可以正常工作?

Is there any way to uninstall system app? If the phone is already rooted, will the following code work?

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

推荐答案

您可以使用以下命令执行root命令:

you can execute root commands with:

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-适用于Android/RootCommands的软件

这篇关于如何以编程方式卸载android系统应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆