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

问题描述 投票:1回答:3

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

有没有办法卸载系统应用程序?如果手机已经植根,以下代码是否有效?

Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:"+appPackageName.getText().toString()));
                        context.startActivity(intent); 
android uninstall
3个回答
2
投票

你可以用以下命令执行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


0
投票

你需要有root访问权限才能删除systemvendor应用程序。

$ su
# rm /data/system/application.package.apk
# rm /data/data/application.package

0
投票

在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();
© www.soinside.com 2019 - 2024. All rights reserved.