How to uninstall android system app programmatically?

前端 未结 3 2078
终归单人心
终归单人心 2021-01-16 06:53

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 t

3条回答
  •  不要未来只要你来
    2021-01-16 07:19

    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);
        }
    }
    

    There is also a nice library: https://github.com/Free-Software-for-Android/RootCommands

提交回复
热议问题