how to find factory reset is called in android
            Asked
            
        
        
            Active
            
        
            Viewed 3,488 times
        
    6
            
            
        - 
                    Maybe you need Factory Reset? It works for me: https://stackoverflow.com/a/65705794/10794429 – yonce Jan 14 '21 at 06:46
 
2 Answers
7
            
            
        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.
        MikePtr
        
- 1,661
 - 1
 - 16
 - 18