Prevent Android App from getting installed on multiple users
Asked Answered
L

3

6

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?

Lui answered 16/1, 2020 at 11:23 Comment(4)
I wonder how you are testing this? If I open multiple users in an emulator with Android 10 and open the guest user no apps I installed on the owner user are shown.Gynecoid
Could you try with a secondary user, not a guest user? See the documents above for the difference. And I'm testing on a real device ... :)Lui
Maybe this can help you #44342190Gynecoid
@Gynecoid That's interesting. Haven't run into a crash yet, but the fact that we need to specify the user is interesting. Cool stuff!Lui
G
3

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

Gynecoid answered 16/1, 2020 at 13:44 Comment(1)
Interesting. Thank you for taking the time to answer.Lui
F
2

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

Falchion answered 19/8, 2020 at 14:50 Comment(0)
D
1

For Android Studio 4.2 GoTo Run > Edit Configurations then Check the Install for all users(For both personal and work profile) and uncheck only for personal profile like in the screenshot below allows for multiple users

Delighted answered 23/6, 2021 at 5:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.