How to uninstall Android App with root permissions

2019-03-03 02:25发布

问题:

I wrote something to uninstall (delete) an App and have now the problem that the apk seems to be deleted but the app is not really deleted from phone..

The supposedly deleted app still exists in the launchers app drawer. And I can open the app, but it force closes the app.

I tested the procedure with an own App (existing at /data/app, not /system/app). With systemapps I didn't test.

Here the code:

private void delApp() {
    String deleteCMD = "rm " + packageInfo.applicationInfo.sourceDir;


    Process process;
    try 
    {
        process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("mount -o remount,rw -t rfs /dev/stl5 /system; \n");          
        os.writeBytes(deleteCMD+"; \n");
        os.writeBytes("mount -o remount,ro -t rfs /dev/stl5 /system; \n");
        os.flush();

    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    }      



}

回答1:

I don't rightly know why what you're doing does not work, maybe someone else can shed some light on that.

You could try:

pm uninstall com.package.name

instead of your rm /package/dir/path method

I'm not sure if that works on apps in the /system/app directory, however.

Also, take a look at: Application launcher icon is not deleted from Home screen when uninstalling android app