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.
-
In Settings > Storage, you can hold down on the Cached data category and delete the cached data of all apps at once. I'm not sure if this will clear the credentials, but it might be useful. – Huey Aug 05 '15 at 12:34
1 Answers
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 separatelypm 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 stringpackage:
, 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
.

- 91,166
- 73
- 343
- 943
-
1+1 that
${app:8}
was a new thing to learn. Thanks for the explanation. @JesseTweed I think a clean-up of comments would be good. :) – Firelord Jul 15 '15 at 18:22 -
@JesseTweed for debugging, ommit the
:8
part to see the content of the$app
variable completely. Also try running just thepm list packages
part alone to see its output. The latter usually produces a bunch of lines in the formatpackage:com.foobar.app
– if that looks different in your case, that will be the issue. What do you get on the latter? Does the format match? If so, it might well be your device's shell doesn't understand the syntax of${app:8}
; then try$(echo $app | awk -F":" '{print $2}')
instead. – Izzy Jul 22 '15 at 13:49 -
Please first things first, Jesse: What does
pm list packages
produce on your device? (the first few lines only – entire output doesn't fit a comment anyway ;) – Izzy Jul 22 '15 at 14:14 -
Hard to believe that that's the output from a simple
pm list packages
(which only lists package names, but prepends no commands). The output in your last comment is rather what the completefor app in $(pm list packages); do echo pm clear ${app:8}; done
would produce: the output you wanted to have – the commands to "clear all app data without performing a factory reset". Though you might wish to check those statements before executing them, to not clear too many apps :) – Izzy Jul 22 '15 at 15:35 -
As that works fine ans smoothly on Linux, and you write something about "cmd" – I assume you're using Windows. The last Windows I used was that one for "Playgroups" back then in the 90s, so I'm afraid I cannot help you much with "Batch scripting". Only thing I can think of is putting the ADB part into a file (e.g.
pmclean.sh
), and then use a double-step:adb push pmclean.sh /sdcard/pmclean.sh
plusadb shell sh /sdcard/pmclean.sh
(optionally followed byadb shell rm /sdcard/pmclean.sh
to remove the script again). – Izzy Jul 22 '15 at 16:33 -
Sorry, as I wrote: With Windows I'm out. You can try finding another place where you might be able to write to (did you really push it to
/sdcard
, and not somewhere else? With Kitkat and above I could imagine a "permission denied" – but a "read-only" rather lets me assume you tried to write somewhere else, e.g./
or/system
). – Izzy Jul 22 '15 at 16:46 -
1I just found this out and figured I should share it here. If you take
adb shell 'for app in $(pm list packages); do echo pm clear ${app:8}; done'
and replace the single quotes with double quotes like thisadb shell "for app in $(pm list packages); do echo pm clear ${app:8}; done"
it will run in a windows batch file. – Jesse Tweed Jul 22 '15 at 18:07 -
Thanks a lot, Jesse! I thought about suggesting that, but with double-quotes it doesn't work on Linux (well, at least not without further modifications – as the local shell would expand the
$variables
intended for the Droid ;) I'll integrate this with my answer – glory for that part goes to you, of course :) – Izzy Jul 22 '15 at 20:05