Is it possible to activate Device Administrator via ADB command instead of tapping

"Setting -> Security -> Device Administrators --> Select App --> Activate"

on handheld?

If it's possible, how?


5 Answers 5


Tested and working on Android 7.0 without root:

adb shell
dpm set-active-admin --user current com.company.foo.bar.package/.the.Admin.Reciever

To find the admin receiver of an installed package, use the following to adb shell command and review the output:

adb shell
pm dump com.company.foo.bar.package | grep ' filter' | cut -d ' ' -f 12 | sort | uniq

To give a real world example, here is the command used to activate IBM's Maas360 Android client as a device admin:

adb shell
pm dump com.fiberlink.maas360.android.control | grep ' filter' | cut -d ' ' -f 12 | sort | uniq

com.fiberlink.maas360.android.control/.receivers.Maas360DeviceAdminReceiver  <-- This is the one I want

Set Device Admin:    
dpm set-active-admin --user current com.fiberlink.maas360.android.control/.receivers.Maas360DeviceAdminReceiver
  • 1
    IT WORKS! This must be the accepted answer! I have one question, is it possible to add an extra to that command? I need to request the Samsung Knox license activation right after the administrator activation and I would like to pass the license's key as an extra (so I do not have to store it in my code or on my device) Commented Jul 8, 2019 at 8:33
  • 1
    Note that dpm set-active-admin is not available on Android 5, but you can get a similar effect using dpm set-device-owner
    – Sam
    Commented Jun 27, 2020 at 11:21
  • This still works in Android 9. Commented Nov 16, 2021 at 22:04
  • The command to get the Receiver does NOT work in here. I tried via Termux and via Terminal Emulator. The command returns nothing. If I use SU, then I get some random numbers. Already checked if the package name is right. Android 9
    – user113550
    Commented Apr 17, 2023 at 1:24
  • Update to my previous comment: for those who the command to get the Admin Receiver of an app don't work, one can find it, if the app is ALREADY an admin, in here: /data/system/device_policies.xml
    – user113550
    Commented Apr 19, 2023 at 11:39

It's not possible. The settings code is specifically written to prevent this. The closest you can come is to bring up the Device Administration Settings page in the Settings app. You can do this with:

adb shell am start -S "com.android.settings/.Settings\$DeviceAdminSettingsActivity"
  • 1
    Thanks Dan, Little correction : it should be adb shell am start -S "com.android.settings/.Settings\$DeviceAdminSettingsActivity" Without single quote
    – marengga
    Commented May 21, 2013 at 4:29
  • In most shells, that command will just start Settings, not the Device administration settings page. Here's Izzy's explanation of why.
    – Dan Hulme
    Commented May 21, 2013 at 9:26
  • 1
    What about disabling? is that possible? Commented Apr 24, 2014 at 21:40

Yes, provided that you've root access. You would have to add the app's receiver and the policy flag in the file /data/system/device_policies.xml. For example, to enable Tasker as Device administrator add the following lines in the said file,

For Android 5.x: Remove the last line with </policies> if there is already a Device Administrator enabled in the system. Simply add the lines in the file after the line with string <policies setup-complete="true">.

<admin name="net.dinglisch.android.taskerm/net.dinglisch.android.taskerm.MyDeviceAdminReceiver">
<policies flags="8" />

For Android 4.2.1: Remove the last line with </policies> if there is already a Device Administrator enabled in the system. Simply add the lines in the file after the line with string <policies>.

<admin name="net.dinglisch.android.taskerm/net.dinglisch.android.taskerm.MyDeviceAdminReceiver">
<policies flags="8" />

Reboot the device for the changes to take effect.

(Busybox required) You can use sed or echo or any command that you're comfortable with to write the file with those lines. For any help, see my answer here: How to enable device administrator for specific apps using Tasker?


you can set the Device as owner from Android Studio. First go to the adb location which is at Platform-tools in Android Sdk and then run the adb shell command. I have give the full path and you can adjust at your requirement upon changing adb path and package name

C:\Users\Owner\AppData\Local\Android\Sdk\platform-tools>adb shell dpm set-device-owner package-name/.MyDeviceAdminReceiver

MyDeviceAdminReceiver is the interface.

  • Note that once an app is set as owner it is very difficult to undo this
    – Sam
    Commented Jun 27, 2020 at 11:38
  • hi @Sam I know but fortunately we can do this through coding to undo the owner Commented Jun 29, 2020 at 3:32

This is possible. You can use android's new tool UI-Automator to click and interact with any view or button on the system including hitting "Activate" for device admin. Here's how:

  1. Get UI-Automator running. (go to "Configure your development environment" and setup a new java project).
  2. Write some code to interact with your preferences list and click "Activate". Example:

    UiScrollable settingsItem = new UiScrollable(new UiSelector().className("android.widget.ListView")); UiObject listButton = settingsItem.getChildByText(new UiSelector().className("android.widget.LinearLayout"), "Enable Device Admin"); listButton.click(); (new UiObject(new UiSelector().text("Activate"))).clickAndWaitForNewWindow(); me.celebrateWith(new Beer());

  3. Compile it: ant build

  4. Push the jar file: adb -d push bin/LookoutTest.jar /data/local/tmp/
  5. Launch your settings activity: adb shell am start -S "'com.android.settings/.Settings\$DeviceAdminSettingsActivity'"
  6. Run the automation: adb -d shell uiautomator runtest LookoutTest.jar -c DALaunch
  7. Party.
  • 1
    Will this work even if the current locale of the device isn't English? Commented Apr 24, 2014 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .