Home » Android » Is it possible to programmatically uninstall a package in Android

Is it possible to programmatically uninstall a package in Android

Posted by: admin April 23, 2020 Leave a comment

Questions:

Can a package uninstall itself? Can a package uninstall another package if they share the same userId and signature?

How to&Answers:

Hey probably too late but this works for me.

Uri packageURI = Uri.parse("package:"+"your.packagename.here");
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
    startActivity(uninstallIntent);

Answer:

A 3rd party app cannot install or uninstall any other packages programmatically, that would be a security risk for Android. However a 3rd party app can ask the Android OS to install or uninstall a package using intents, this question should provide more complete information:

install / uninstall APKs programmatically (PackageManager vs Intents)

Answer:

In Kotlin, using API 14+, you can just call the following:

startActivity(Intent(Intent.ACTION_UNINSTALL_PACKAGE).apply {
     data = Uri.parse("package:$packageName")
})

Or with Android KTX:

startActivity(Intent(Intent.ACTION_UNINSTALL_PACKAGE).apply {
     data = "package:$packageName".toUri()
})

It will show the uninstall prompt for your app. You can change packageName to any package name of another app if needed.

Answer:

Third Party app cannot Uninstall App Silently!

Either you need to become System App to get DELETE_PACKAGES Permission else you need to show Uninstall Popup (User Confirmation)

Alternatively, you can take Accessibility permission and then by showing an Accessibility Overlay you can tell your service to click on Uninstall button! But that will be privacy violation.