/** * Use code to clear the app's data * Usually when we clear the app's data, we mostly find the app in the settings * and then select its erase data. The code implementation is given below. * NOTE: * 1 device requires root * 2 Note a newline is required at the end of the command \ n * This is equivalent to the fact that we usually enter a command in DOS and then wrap it. * otherwise the command will not execute. */private void Cleandata (S Tring PackageName) {try {System.out.println ("---> 9527 start clearing" +packagename); Process su= runtime.getruntime (). EXEC ("su"); String cmd = "rm-r" + "/data/data/" +packagename;cmd = cmd + "\ n exit\n";//The following two sentences represent restarting the device//string cmd = "reboot";//cmd = cmd + "\ n exit\n "; Su.getoutputstream (). Write (Cmd.getbytes ()), if ((Su.waitfor ()! = 0)) {throw new SecurityException ();}} catch (Exception e) {System.out.println ("---> 9527 clear Data e=" +e.tostring ());}}