Ask for password before uninstalling application

you should try something like the following :

1st – declare your broadcast recevier in the Manifest file , that will listen to QUERY_PACKAGE_RESTART :

  <receiver android:name=".UninstallReceiver">
          <intent-filter android:priority="999999">
                <action android:name="android.intent.action.QUERY_PACKAGE_RESTART" />
                <data android:scheme="package" />
          </intent-filter>
     </receiver>

2nd – your UnunstallIntentReceiver java class like the following :

public class UninstallReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // fetching package names from extras
        String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES"); 

        if(packageNames!=null){
            for(String packageName: packageNames){
                if(packageName!=null && packageName.equals("application_package")){
                   // start your activity here and ask the user for the password 
                }
            }
        }
    }

    }

and please give me some feedback

Hope That Helps.

Leave a Comment