how to find factory reset is called in android
Old topic but maybe will help someone.
There is not any official event which states that Factory Data Reset will be performed. However for Android <= 22 (Lollipop) there is unofficial (hidden in the code) broadcast intent android.intent.action.MASTER_CLEAR which is fired when External Storage will be formatted. If you click factory reset for Android Settings then MASTER_CLEAR intent is fired, in the result you can state that there will be factory reset.
Sample code:
// Class Member
private BroadcastReceiver receiver;
.
.
.
// In some method, e.g. onCreate()
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.ACTION_SHUTDOWN");
filter.addAction("android.intent.action.MASTER_CLEAR");
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(
Intent.ACTION_SHUTDOWN)) {
Log.d(TAG, "SHUTDOWN")
}
if (intent.getAction().equals("android.intent.action.MASTER_CLEAR")) {
Log.d(TAG, "FACTORY DATA RESET")
}
};
registerReceiver(receiver, filter);
If there will be factory reset then you will see MASTER_CLEAR action followed by SHUTDOWN action. I tested on Nexus 5 and Androids 4.4.4, 5.0, 6.0, 6.0.1 and works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With