2

I have been through with many Google solutions but not any solution is able to resolve my problem. What I am trying to do is firing a window for user to enter pin/password while he is trying to uninstall my application.

I saw this link, but I am facing 2 issues with this solution these are as follow:

  1. I registered broadcast receiver in My Application, when I open "My Application" in settings, it does not seems working but working fine with other apps. My Code below:

    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("com.android.systemapplication")){
                // User has selected our application under the Manage Apps settings
                // now initiating background thread to watch for activity
                new ListenActivities(context).start();
            }
          }
       }
    }
    
  2. When I replaced package name with some different package name that settings screen can detect in broadcast receiver then in run(thread) it is not detecting uninstaller activity, Please see my ListenActivities as below:

    public void run(){
    
    Looper.prepare();
    
    while(!exit){
    
         // get the info from the currently running task
         List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(MAX_PRIORITY); 
    
         String activityName = taskInfo.get(0).topActivity.getClassName();
    
    
         Log.d("topActivity", "CURRENT Activity ::"
                 + activityName);
    // here "activityName" is "com.android.launcher" if I select 
    // package name it is "com.android.launcher2.launcher".
    
         if (activityName.equals("com.android.packageinstaller.UninstallerActivity")) {
            // User has clicked on the Uninstall button under the Manage Apps settings
    
             //do whatever pre-uninstallation task you want to perform here
    
             exit = true;
             Toast.makeText(context, "Done with preuninstallation tasks... Exiting Now", Toast.LENGTH_SHORT).show();
        } else if(activityName.equals("com.android.settings.ManageApplications")) {
            // back button was pressed and the user has been taken back to Manage Applications window
                      // we should close the activity monitoring now
            exit=true;
        }
    }
    Looper.loop();
    }
    

I saw many solutions but no success. if it is deprecated then please show some Android documentation because I can see antivirus can do same as what I am asking for. Code would be more helpful. ? Any help would be helpful.

Community
  • 1
  • 1
Shivv
  • 65
  • 2
  • 11

0 Answers0