Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use adb to install and debug an app in a work profile?

Tags:

android

adb

I developed an android app which works fine. But if I install it into a Work Profile, it sometimes fails. The installation into a Work Profile is currently done by distributing the app via a private Google PlayStore (only company users will be able to download it).

Any way I can use 'adb' to install the apk into Work Profile directly? And I need to debug the app running inside a Work Profile as well.

like image 772
GummyBear21 Avatar asked Dec 07 '18 03:12

GummyBear21


People also ask

Can you install apps using adb?

ADB (Android Debugging Bridge) can be used to execute commands on your VR device. It's mostly used to install applications (APK files) from a Windows PC or Mac with a device connected with USB.

How do I use adb Installer?

To use adb with a device connected over USB, you must enable USB debugging in the device system settings, under Developer options. To use adb with a device connected over Wi-Fi, see Connect to a device over Wi-Fi. On Android 4.2 and higher, the Developer options screen is hidden by default.


2 Answers

Here you find the documentation for adb which is used to install and start the app: http://developer.android.com/tools/help/adb.html

You see there that (unfortunately) it is not possible to install the app for only one user. But it is possible to start and debug it "in the name" of a specific user.

So what you have to do is the following:

  1. find out the userId of the desired user
  2. set the userId in your Run Configuration

Step 1

To find out the userId of the desired user, open your terminal and enter

$> adb shell dumpsys user

You'll get a list about all the user information of the connected device. Somewhere in this list you should also find your user similar to this: UserInfo{10:Work profile:30}

This means that 10 is your userId.

Step 2

Now go to AndroidStudio -> Run -> Edit Configurations. Select your current Run Configuration and in the field for Launch Flags enter --user 10

If you click the Run or Debug button now, the app will be installed for all user and started with the user with userId 10

like image 104
muetzenflo Avatar answered Sep 21 '22 22:09

muetzenflo


As a complement to @muetzenflo's answer, in case you want to run your application via command-line, all you need to do is:

$ adb shell pm list users

Output will be similar to this:

UserInfo{0:Drew:13} running
UserInfo{10:Work profile:30} running

Get the user id of your work profile and call am start with --user flag:

$ adb shell am start --user 10 \
  -n "com.example.myapp/com.example.myapp.testactivity" \
  -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

You can read more at Android's official page on Work profiles.

like image 37
volpato Avatar answered Sep 20 '22 22:09

volpato