1

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); 
Zahid Hasan
  • 555
  • 1
  • 6
  • 12
  • Below link may be helpful. http://stackoverflow.com/questions/6813322/install-uninstall-apks-programmatically-packagemanager-vs-intents – Pradeep PK Dec 21 '15 at 15:07

3 Answers3

3

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

Fabian
  • 960
  • 13
  • 26
0

You need to have root access in order to remove system or vendor apps.

$ su
# rm /data/system/application.package.apk
# rm /data/data/application.package
Andrey Kopeyko
  • 1,556
  • 15
  • 14
0

Try this on Rooted Device...it works

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