47

How can I do the factory reset in android using ADB command? I had used adb reboot recovery command to get reset. But third party applications couldn't be cleared somehow.Is it correct way to achieve using ADB?

Actually, I want to do factory reset android devices through java code. What can be solution here?

peterh
  • 11,875
  • 18
  • 85
  • 108
Prashant
  • 1,351
  • 3
  • 20
  • 32
  • Also see http://stackoverflow.com/questions/10817721/wipe-data-factory-reset-through-adb -- same answers though. – Ehtesh Choudhury Apr 26 '13 at 23:05
  • 3
    I’m voting to close this question because it is offtopic here (but ontopic on the https://android.stackexchange.com). – peterh Dec 15 '20 at 10:57

4 Answers4

91

You can send intent MASTER_CLEAR in adb:

adb shell am broadcast -a android.intent.action.MASTER_CLEAR

or as root

adb shell  "su -c 'am broadcast -a android.intent.action.MASTER_CLEAR'"

After Android 8.0 and above with root permission from shell

am broadcast -p "android" --receiver-foreground -a android.intent.action.FACTORY_RESET
ArkadiBernov
  • 570
  • 8
  • 13
0x8BADF00D
  • 7,138
  • 2
  • 41
  • 34
  • 1
    Amazing, didn't think that it would work, but in my case it helped! (it was a cheap overmax tablet, where I couldn't even access fastboot, nor recovery --wipe_data helped!) Thanks! – original.roland Oct 01 '16 at 15:00
  • Note: On most devices you will need to be root for this to work, else you will not have the appropriate permission to send this broadcast. Before running this command, use `adb root` to restart your phone's shell with root privileges – Hamy Mar 27 '17 at 17:46
  • This command is not working in Android-OMR1 saying background execution not allowed. – Sudhir Sinha Apr 10 '18 at 07:27
  • This works for Devices which are rooted. But if Device is not Rooted than it is not working. It Doesn't give any response. Any Idea? – yash Apr 10 '18 at 10:00
  • I just get Broadcasting: Intent { act=android.intent.action.MASTER_CLEAR } Broadcast completed: result=0 :( – Francisco Peters Apr 19 '18 at 15:05
  • @TheClansman Same output i am having when i try with non rooted device. Did you find any other solution for this? – yash May 09 '18 at 10:05
  • Worked for me on non-rooted device, just did adb root then adb shell am broadcast -a android.intent.action.MASTER_CLEAR – Tom Bryant Jan 29 '19 at 12:30
  • You must reboot the device after you run the command, so you can just type 'am broadcast -a android.intent.action.MASTER_CLEAR; reboot' and it will reset the device. – wuseman Aug 11 '19 at 23:31
  • Worked on rk3188 tablet. Thank you! – Stephan Richter Feb 15 '20 at 10:34
  • 1
    didn't quite work for me due to background execution/implicit intent restrictions that have been introduced, see here for my solution: https://blog.deanwild.co.uk/android-factory-reset-via-adb-intent – Dean Wild Apr 04 '22 at 11:04
21

Try :

adb shell
recovery --wipe_data

And here is the list of arguments :

* The arguments which may be supplied in the recovery.command file:
 *   --send_intent=anystring - write the text out to recovery.intent
 *   --update_package=path - verify install an OTA package file
 *   --wipe_data - erase user data (and cache), then reboot
 *   --wipe_cache - wipe cache (but not user data), then reboot
 *   --set_encrypted_filesystem=on|off - enables / diasables encrypted fs
Community
  • 1
  • 1
EvZ
  • 11,889
  • 4
  • 38
  • 76
15

Warning

From @sidharth: "caused my lava iris alfa to go into a bootloop :("


For my Motorola Nexus 6 running Android Marshmallow 6.0.1 I did:

adb devices       # Check the phone is running
adb reboot bootloader
# Wait a few seconds
fastboot devices  # Check the phone is in bootloader
fastboot -w       # Wipe user data
Luke Singham
  • 1,536
  • 2
  • 20
  • 38
Robin Winslow
  • 10,908
  • 8
  • 62
  • 91
14

I have made it from fastboot mode (Phone - Xiomi Mi5 Android 6.0.1)

Here is steps:

# check if device available
fastboot devices
# remove user data
fastboot erase userdata
# remove cache
fastboot erase cache 
# reboot device
fastboot reboot
Den Kison
  • 1,074
  • 2
  • 13
  • 28