Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Android App from getting installed on multiple users

When I run my app from Android Studio and install it on the primary user on a device, I notice that it gets installed on the secondary user as well.

In the first place, why is this happening? The android:requiredForAllUsers flag is false by default, and in any case can only be used by system apps or pre-installed apps.

Or is it the case that this happens only for debug-mode apps installed via Android Studio?

How can I prevent this from happening?

It is critical for my app that it be installed on one user only. I have already read the following documents:

Supporting Multiple Users

Manage multiple users

Neither of those documents has any explanation of whether and how the installation process is affected by the multi-user feature.

There must surely be some manifest or build setting that permits or prevents installation on multiple users. Why isn't it easier to find? And why isn't this question more common on SO?

like image 953
Y.S Avatar asked Jan 16 '20 11:01

Y.S


2 Answers

You don't prevent it, you do what you need to do: in this case it would be defining your run configuration so the app gets only installed where you want, because per default it gets installed everywhere I suppose. You can do this by specifying the flag --user user_id. You can get the id with adb shell pm list users

Reference: Android Studio 2.3.2 Launching the app under a work profile or another user account on the target device will result in a crash

like image 153
David Avatar answered Sep 18 '22 01:09

David


The easiest way is to add the --user current flag to launch configs.

Select Launch Configurations

enter image description here

The under Install Flags, add the flag --user current. This will ensure the app is only installed on the current user and not on any guest acconuts.

enter image description here

like image 27
Kiran Rao Avatar answered Sep 20 '22 01:09

Kiran Rao