Answer the question
In order to leave comments, you need to log in
How to programmatically delete an application in Android?
There is a list of ApplicationInfo objects . I need to display dialog boxes one by one, where the user can refuse or remove the application from his phone.
val packageURI = Uri.parse("package:${it.packageName}")
val intent = Intent(Intent.ACTION_DELETE, packageURI)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
val packageInstaller: PackageInstaller = context.packageManager.packageInstaller
packageInstaller.uninstall(
packageName,
createUninstallIntentSender(context, packageName)
)
private fun createUninstallIntentSender(
context: Context,
packageName: String
): IntentSender {
val intent = Intent(ACTION_UNINSTALL_COMPLETE)
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName)
val pendingIntent = PendingIntent.getBroadcast(
context, 0,
intent, 0
)
return pendingIntent.intentSender
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question