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?
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?
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
Output:
…
com.fiberlink.maas360.android.control/.receivers.GoogleCampaignReceiver
com.fiberlink.maas360.android.control/.receivers.LocalEventReceiver
com.fiberlink.maas360.android.control/.receivers.Maas360DeviceAdminReceiver <-- This is the one I want
com.fiberlink.maas360.android.control/.receivers.Maas360SecondaryDeviceAdminReceiver
…
Set Device Admin:
dpm set-active-admin --user current com.fiberlink.maas360.android.control/.receivers.Maas360DeviceAdminReceiver
dpm set-active-admin
is not available on Android 5, but you can get a similar effect using dpm set-device-owner
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"
adb shell am start -S "com.android.settings/.Settings\$DeviceAdminSettingsActivity"
Without single quote
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" />
</admin>
</policies>
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" />
</admin>
</policies>
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.
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:
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());
Compile it: ant build
adb -d push bin/LookoutTest.jar /data/local/tmp/
adb shell am start -S "'com.android.settings/.Settings\$DeviceAdminSettingsActivity'"
adb -d shell uiautomator runtest LookoutTest.jar -c DALaunch