Android File Delete deleteApkInSystem(String fileName, int type)

Here you can find the source of deleteApkInSystem(String fileName, int type)

Description

delete Apk In System

Declaration

private static void deleteApkInSystem(String fileName, int type)
            throws IOException, InterruptedException 

Method Source Code

//package com.java2s;

import java.io.DataOutputStream;

import java.io.IOException;

public class Main {

    public static int USER_APP = 1;
    public static int SYSTEM_APP = 2;

    private static void deleteApkInSystem(String fileName, int type)
            throws IOException, InterruptedException {
        String[] commands = null;
        if (type == USER_APP) {
            commands = new String[] { "sysrw",
                    "/system/bin/rm " + "/data/app/" + fileName, "sysro" };
        } else if (type == SYSTEM_APP) {
            commands = new String[] { "sysrw",
                    "mount -o remount rw /system/",
                    "/system/bin/rm " + "/system/app/" + fileName, "sysro" };
        }// ww w  . jav  a  2 s.co  m

        runAsRoot(commands);
    }

    public static void runAsRoot(String[] commands) throws IOException,
            InterruptedException {
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        for (String cmd : commands) {
            os.writeBytes(cmd + "\n");
        }
        os.writeBytes("exit\n");
        os.flush();
        os.close();
        p.waitFor();
    }
}

Related

  1. delete(File f)
  2. delete(File file)
  3. delete(File toDelete)
  4. deleteAll(File file)
  5. deleteAndRename(File toDelete, File toRename)
  6. deleteDatabaseFile(int type, Context context)
  7. deleteDir(File dir)
  8. deleteDir(File dir)
  9. deleteDir(File spec)