Smart
Smart

Reputation: 445

ROOT - Uninstall app in background without prompt dialog

Hi guys i have a rooted phone based on Android 7.1.1 and i want uninstall apps without prompt the dialog (back or uninstall confirmation). My app has root privilege and it is also a system app. I have tried to use shell command via "pm uninstall" command but it doesn't works:

Runtime.getRuntime().exec("su pm uninstall " + packageName);

I got "Magisk/E: Unknown id: pm". I tried many other combination, with shell prefix etc but nothing. Root works very well and in manifest file i put the perm "DELETE_PACKAGES". The same command works if i execute it via PC.

How i can do to uninstall an app without dialog ?

Upvotes: 0

Views: 525

Answers (2)

Iakovos
Iakovos

Reputation: 1982

Instead of Runtime.getRuntime().exec("su pm uninstall " + packageName); try running Runtime.getRuntime().exec("su -c 'pm uninstall " + packageName + "'");

In your code you have forgotten to add -c, so pm uninstall [...] is regarded as arguments of the su command.

Upvotes: 2

Colibri
Colibri

Reputation: 733

You could try this using DataOutputStream:

        try
        {
            Process p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            os.writeBytes("pm uninstall " + packageName + "\n");
            os.writeBytes("exit\n");
            os.flush();

            p.waitFor();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        } catch (InterruptedException e)
        {
            e.printStackTrace();
        }

Upvotes: 0

Related Questions