An old topic, but maybe it will help someone.
The official event does not indicate that Factory Data Reset will be executed. However, for Android <= 22 (Lollipop) there is an unofficial (hidden in the code) translation of the intent android.intent.action.MASTER_CLEAR, which starts when formatting the external storage. If you click Factory Reset for Android settings, then MASTER_CLEAR is washed, as a result you can specify that there will be Factory reset.
Code example:
private BroadcastReceiver receiver;
.
.
.
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);
Factory Reset, MASTER_CLEAR, SHUTDOWN. Nexus 5 Androids 4.4.4, 5.0, 6.0, 6.0.1 .