Question

My App uses a DevicePolicyManager. If my users want to uninstall the app they have to do following steps:

SETTINGS -> Location and Security-> Device Administrator

deselect my App and then thay can uninstall it

I think that is not a good solution for a Play Store app. Can I do these steps for my users in the code so they can uninstall my app easily from their launcher?

Was it helpful?

Solution

Yes you can. Do it like this:

  DevicePolicyManager dpm;
 ComponentName admin;
          try
          {
            dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
            admin = new ComponentName(YourActivity.class, AdminReceiverActivity.class);
            if(dpm.isAdminActive(admin))
            {
                dpm.removeActiveAdmin(admin);
            }
          }
     catch(Exception e)
     {
        e.printStackTrace(); 
     } 
     finally
     { 
          Intent intent = new Intent(Intent.ACTION_DELETE);
          intent.setData(Uri.parse("package:" + this.getPackageName()));
          startActivity(intent)
     }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top