问题
Let's say we have a Work Profile (Android For Work) enabled in Android device. Does anyone know how to install an APK via ADB in Work Profile rather than personal profile.
I have seen the ADB documentation and there's a way to get the User ID but using the same ID I am unable to install an APK.
To get ID : adb shell pm list users
Install command : adb install -r --user 12 app_name.apk
Error message :
Performing Streamed Install
adb: failed to install app-prodDebug.apk: Security exception: Shell does not have permission to access user 12
com.android.server.am.ActivityManagerService.handleIncomingUser:22541 android.app.ActivityManager.handleIncomingUser:3989 com.android.server.pm.PackageManagerShellCommand.translateUserId:2434
java.lang.SecurityException: Shell does not have permission to access user 12
com.android.server.am.ActivityManagerService.handleIncomingUser:22541 android.app.ActivityManager.handleIncomingUser:3989 com.android.server.pm.PackageManagerShellComma
Any way to get around this ? My use case here is to replace an App with debug option enabled so that I can troubleshoot any issue that is happening with that specific app which is installed in work profile.
回答1:
adb push android.apk /data/local/tmp
adb shell pm install --user 12 /data/local/tmp/android.apk
回答2:
Above solution from @jtmcodle works fine.
But to findout userid please use below command
adb shell dumpsys user
In my case above command gave following output
UserInfo{11:10100030} serialNo=11
So I ran below command to make it work
adb shell pm install --user 12 /data/local/tmp/android.apk
来源:https://stackoverflow.com/questions/56951666/install-apk-in-work-profile-via-adb-in-android