Background
The normal way to call for the uninstallation an app is simply by using the "ACTION_DELETE" intent :
startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" +packageName)));
The problem
starting with some Android version (don't remember which) , apps can be installed for multiple users on the same device.
This means there is a new way to uninstall an app, one which will uninstall it for all users (image taken from Lollipop - Android 5.0 ) :
The question
I've searched in the documentation, but couldn't find the answer those questions:
Is there any way to perform this operation via an intent? Maybe something to add to the intent I've written above ?
Does ADB have a new command to remove an app for all users?
Is there a way to check if an app is installed for multiple users?
Yes, but be careful. You can pass in
Intent.EXTRA_UNINSTALL_ALL_USERS
.However, it's hidden because it:
You could just pass in the constant anyway, if you feel it's necessary and disagree with Google on that one. Just for example, here are the differences between passing in
false
andtrue
with that constantResults
No, the command remains the same.
This will remove that app for all users. I'm unaware of a way to specify a particular user.
No, not that I'm aware of. In fact, when the Settings apps decides to place the "Uninstall for all users" option in the options menu, it's basically doing so based on whether or not there are multiple users period, not if both the current user and another user have an app installed.
Not to mention, most of the methods in
UserManager
that you'd need to even tell if there are multiple users on the device, likeUserManager.getUserCount
, require theMANAGE_USERS
permission which is a system API and hidden. So, I'm not even sure why that's a public method.Also, you can easily test all of your questions, much like I did, by creating a dummy user on your device. You don't even need to log into a Google account.