Can't set device owner on Samsung device with Android 11

1.3k Views Asked by At

I'm trying to set my app as a device owner on the Samsung A51 with Android 11. It's a fresh device with no accounts added:

adb shell dpm set-device-owner <package>/<package>.receiver.AdminReceiver
java.lang.RuntimeException: Can't set package ComponentInfo{<package>/<package>.receiver.AdminReceiver} as device owner.
    at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:204)
    at com.android.commands.dpm.Dpm.onRun(Dpm.java:115)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:60)
    at com.android.commands.dpm.Dpm.main(Dpm.java:41)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:409)

There's an active built-in device admin:

adb shell dumpsys device_policy
Current Device Policy Manager state:
  
  
  
  Enabled Device Admins (User 0, provisioningState: 0):
    com.samsung.android.kgclient/.receiver.KGAdminReceiver:
      uid=10089
      testOnlyAdmin=false

This method works on other devices, but not on this Samsung. Why and how to fix it?

P.S. I've already read all (or almost all) similar topics on SO.

1

There are 1 best solutions below

0
On

I think you cannot set your app as a device owner because your app not yet has device admin permission. You must set your app as a device admin, then you can set your app to be device owner. Use this command to set your app as a device admin.

adb shell dpm set-active-admin <package>/<package>.receiver.AdminReceiver

Then you can use your command to set your app as a device owner

adb shell dpm set-device-owner <package>/<package>.receiver.AdminReceiver

It works for me ^^ you can try it.