/** * Use code to eliminate app data * We are not unusual to clear the app data, find the appropriate app * and then select its erase data. The following is a code implementation. * * NOTE: * 1 device requires root * 2 The Demo sample removes the system-level app * 2 Note that you need to add a newline at the end of the command \ n * This is equivalent to the fact that we usually enter the command in DOS and then wrap it. * otherwise the command will not be run. */pri vate void Cleandata (String packagename) {try {System.out.println ("---> 9527 starts clear" +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 ());}}
The following code was updated: August 10, 2014 00:15:36
/** * Use code to clear the app's data * Most of the time, 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. * * In the above section of the code to remove all the things under the data/data/packagename. * So it is necessary to restart the device, because its lib has been deleted. * After the device restarts, it will voluntarily generate a new LIB the System application talent enough to perform properly. * In order to avoid restarting the device, the Lib directory should not be removed while the data is being cleaned, such as the following code. * * * NOTE: * 1 device requires root * 2 The demo example removes the system-level application * 2 Note that a newline is required at the end of the command \ *
> This is the equivalent of having to enter a command in DOS and then change the line. * Otherwise the command will not be executed. */private void Cleandata (String packagename) {try {Process su= runtime.getruntime (). EXEC ("su"); String cmd = "cd/data/data/" +packagename+ ";" + "Rm-r ' ls|grep-v lib '"; SYSTEM.OUT.PRINTLN ("------cmd=" +cmd); 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 ());}}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Android uses code to eliminate app data and restart device