Android uses code to eliminate app data and restart device

Source: Internet
Author: User

/** * 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.