Java tutorial
//package com.java2s; //License from project: Apache License import android.util.Log; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { private static final String CMD_CLEAR_APP_DATA = "pm clear "; public static void clearAppData(String packageName) { String s = do_exec_with_root(CMD_CLEAR_APP_DATA + packageName); Log.d("TAG", "clear data result is " + s + ".........."); } public static String do_exec_with_root(String cmd) { String s = "\n"; try { Process su_p = Runtime.getRuntime().exec("su"); DataOutputStream dataOutputStream = new DataOutputStream(su_p.getOutputStream()); dataOutputStream.writeBytes(cmd + "\n"); dataOutputStream.writeBytes("exit" + "\n"); dataOutputStream.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(su_p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { s += line + "\n"; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return s; } }