Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete app intent not working on android pie

This worked in the past but does not work on my android pie device anymore (worked until the recent pie update):

fun uninstallApp(packageName: String) {
    val packageURI = Uri.parse("package:$packageName")
    val intent = Intent(Intent.ACTION_DELETE, packageURI)
    intent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    startActivity(intent )
}

I could not find any documentation that indicates that this intent is not working anymore.

Does anyone know if there is an alternative way to open the uninstall dialog on android pie?

like image 536
prom85 Avatar asked Feb 08 '19 18:02

prom85


People also ask

Is intent deprecated?

The Intent is not deprecated the problem is with your itemClickable. class because it is not recognized.

What is android intent action view?

An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object.

What is the use of intent createChooser () method?

The system will always present the chooser dialog even if the user has chosen a default one. If your intent created by Intent. createChooser doesn't match any activity, the system will still present a dialog with the specified title and an error message No application can perform this action .

What is implicit intent?

Implicit Intent Using implicit Intent, components can't be specified. An action to be performed is declared by implicit intent. Then android operating system will filter out components that will respond to the action.


1 Answers

The code will still work, supposedly the app is not requesting the permission to execute it.

Since Android Pie (Android 9), apps are required to declare that they request apps to be deleted. This can be done by adding this permission to the AndroidManifest.xml:

<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>

* Note that it is not needed to request this permission at runtime. Declaring this in the Manifest is enough for it to work.


Also, we could use the ACTION_UNINSTALL_PACKAGE action instead for the request of removing packages. For this action, the documentation is mentioning that the permission stated above is required for it to work since Android Pie.

like image 59
Alex Avatar answered Oct 22 '22 23:10

Alex