Search code examples
androidandroid-package-managers

Uninstall APKs programmatically for all user


To uninstall app i got a solution from stackoverflow but i need to uninstall apk from all users
This code will will uninstalling only for current user but if the user is admin or main user i need to perform uninstall for all user. How to do it?

Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.example.mypackage"));
startActivity(intent);

Above code copied from install / uninstall APKs programmatically (PackageManager vs Intents)
Note: This is not a duplicate question


FAQ
What is mean by multiple user?

In Android What is mean by multiple user?


Solution

  •     final Uri packageURI = Uri.parse("package:" + "package:com.example.mypackage");
        final Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
        uninstallIntent.putExtra("android.intent.extra.UNINSTALL_ALL_USERS", false or true);
        startActivity(uninstallIntent);
    

    You can check out this answer from where I've taken reference - Is there an intent for uninstallation of an app for ALL users?

    What is mean by multiple user?

    If you have a used laptop or machine, then you may already be familiar with the concept here: Where you can create multiple accounts with different roles. It’s like having multiple machines wrapped into one.

    Android has a very similar feature built in called User Profiles. It will create a separate profiles where one can make changes and keep multiple settings. But yeah when users installs app it will automatically will be installed in all profiles so end user need manually uninstall it in the profile where it is not required.

    I tried using this in my device but performance is bit slow after I added multiple profile.