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.
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.
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.
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:
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With