L
L
Lordao2020-03-06 17:30:39
Android
Lordao, 2020-03-06 17:30:39

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)

This code displays the dialog box as it should, but without a callback where I can find out what the user has selected, so that I can then display the next dialog box.

Also tried to uninstall using PackageInstaller , but nothing is uninstalled or shown.

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 question

Ask a Question

731 491 924 answers to any question