在安卓系统中如何通过adb进行恢复出厂设置?

47

如何使用ADB命令在Android中进行恢复出厂设置?我已经使用了adb reboot recovery命令来进行重置。但是第三方应用程序无法被清除。这是使用ADB实现的正确方法吗?

实际上,我希望通过Java代码对Android设备进行恢复出厂设置。这里有什么解决方案?


另请参见https://dev59.com/IWgv5IYBdhLWcg3wJNdF尽管答案相同。 - Ehtesh Choudhury
3
我建议关闭这个问题,因为它在这里不是主题(但在 https://android.stackexchange.com 上是主题)。 - peterh
4个回答

91

您可以在adb中发送意图 MASTER_CLEAR

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

或作为root用户

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

在Android 8.0及以上版本中,使用shell具有root权限

am broadcast -p "android" --receiver-foreground -a android.intent.action.FACTORY_RESET

1
太神奇了,没想到它真的起作用了,在我的情况下非常有帮助!(这是一款便宜的overmax平板电脑,我甚至无法访问fastboot或恢复模式——wipe_data帮了我大忙!)谢谢! - original.roland
注意:在大多数设备上,您需要获取 root 权限才能使此命令生效,否则您将没有适当的权限来发送此广播。在运行此命令之前,请使用 adb root 以 root 权限重新启动您手机的 shell。 - Hamy
这个命令在Android-OMR1中无法工作,提示不允许后台执行。 - Sudhir Sinha
这适用于已经取得Root权限的设备。但如果设备没有Root权限,则无法运行。它不会给出任何响应。有什么想法吗? - yash
1
由于引入了后台执行/隐式意图限制,这对我来说并不起作用,请参阅此处以获取我的解决方案:https://blog.deanwild.co.uk/android-factory-reset-via-adb-intent - Dean Wild
显示剩余5条评论

21

尝试:

adb shell
recovery --wipe_data

这里是参数的列表:

* 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

嗨 EvZ, adb shell recovery --wipe_data 会清除第三方应用程序吗? - Prashant
应该是我之前用过的,但你可以试试看。 - EvZ
2
@EvZ 最终出现了“分段错误”。有什么线索吗? - kmonsoor
5
如果你遇到"segment fault"错误,尝试执行以下命令:adb shell wipe data; adb reboot; - Lucas D'Avila

15

警告

来自@sidharth: "导致我的Lava Iris Alfa陷入了启动循环:("


对于我的运行Android Marshmallow 6.0.1的Motorola Nexus 6,我执行了以下操作:

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

3
我的Lava Iris Alfa出现了启动循环问题 :( - Sidharth
@Sidharth 哦不!你认为我应该删除这个答案 - 如果它很危险的话?或者希望你的评论已经足够警示了。 - Robin Winslow
1
我猜你可以编辑你的回答并为其他人发出警告。 - Sidharth
我的手机在使用这个解决方案后卡住了。幸运的是,另一个解决方案帮助我解决了问题(我的手机是小米mi5,安卓版本为6.0.1)。 - Den Kison

14

我已经从fastboot模式中恢复了(手机-小米Mi5 Android 6.0.1)

以下是步骤:

# check if device available
fastboot devices
# remove user data
fastboot erase userdata
# remove cache
fastboot erase cache 
# reboot device
fastboot reboot

我必须先使用adb reboot bootloader,但它起作用了。 - Vitor Oliveira
在执行这些命令之前,我必须使用 adb rootadb reboot bootloader 命令,否则我的设备会卡住。 - NightFury

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接