Here you can find the source of deleteApkInSystem(String fileName, int type)
private static void deleteApkInSystem(String fileName, int type) throws IOException, InterruptedException
//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(); } }