Will
Will

Reputation: 20191

Is it possible to programmatically uninstall a package in Android

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

Upvotes: 40

Views: 34858

Answers (4)

Robby Lebotha
Robby Lebotha

Reputation: 1255

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

Upvotes: 23

Dhruv Kaushal
Dhruv Kaushal

Reputation: 670

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.

Upvotes: 1

Louis CAD
Louis CAD

Reputation: 11529

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.

Upvotes: 1

satur9nine
satur9nine

Reputation: 15042

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)

Upvotes: 8

Related Questions