Friday, May 29, 2015

4.1 jelly bean - Clearing all the app data on an Android tablet without using factory reset?


In Android, is there a way to clear all the app data at the same time without using the factory reset? I work at a library and we have Android Tablets for checkout for patrons to use and after the patron is done using the tablet we want to delete the username off any and all apps the patron may have used so that their username is not left on the app. I know the "Clear Data" button in Application Manager will clear the username but we would have to do this for every app and would rather do this in one instance rather then one at a time. Any help will be greatly appreciated.



Answer



That could be done via ADB and a little scripting – though I'm currently not sure whether it might require root (surely you understand I do not want to try that on any of my working devices right now ;):



#!/system/bin/sh

for app in $(pm list packages); do
pm clear ${app:8}
done

This snippet you could save into a file (e.g. clear_data.sh), or directly execute per copy-paste when connected to the device using adb shell.




Some explanation of what that does, as there was some trouble on the OP's end:



  • pm list packages gives a list with package names of all installed apps, one per line.

  • for app in $(pm list packages); do would loop over that list, and execute the "inner command" for each package separately


  • pm clear ${app:8} deletes the data from each package specified by $app, cutting of the first 8 chars (pm list prepends each app name by the string package:, which we need to cut off)


To verify at the command line, you can copy-paste the following one-liner:


adb shell 'for app in $(pm list packages); do echo pm clear ${app:8}; done'

(note: when run from a Windows command line, you'll have to use double quotes (thanks to Jesse for this hint!) – on Linux/Unix/Mac stay with the single quotes or the variables would be expanded "on the wrong end")


That's a "dry run", not doing anything but listing the commands above code block would execute directly. You could use the output from that to delete the data from each app manually, picking the ones you're interested in.1


To give an example command produced by this: pm clear com.facebook.katana would delete the data of the Facebook app.




1: This might prove to be an important part, as the loop would really clear data from all apps (including system apps) – which might not be exactly what you're after. You can automatically restrict that to e.g. user-apps by passing the parameter -3 (for "3rd party apps only") to the pm list command, i.e. pm list packages -3.



No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...