Install app as a device administrator

The following instructs how to set an app as a device admin. This can be useful for several things, mostly for running an app in kiosk mode. Being a device admin enables such an app to pin the screen, to prevent the lock screen, and prevents it from being uninstalled by the user without permission from the app.

Note that device administration functions are deprecated, and will be removed from Android soon. Also note that it is ineffective on Wear OS.


Include a BroadcastReceiver that takes care of being an admin, like so:

package com.pixplicity.example
import android.content.ComponentName
import android.content.Context

class ExampleDeviceAdminReceiver : DeviceAdminReceiver() {
    companion object {
        fun getComponentName(context: Context): ComponentName {
            return ComponentName(context.applicationContext,


Add the following inside the <application> tag:

        android:resource="@xml/device_admin_receiver" />
        <action android:name="" />

and add this file to the res/xml/ folder of your module:

<?xml version="1.0" encoding="utf-8"?>
        <limit-password />
        <watch-login />
        <reset-password />
        <force-lock />
        <wipe-data />
        <expire-password />
        <encrypted-storage />
        <disable-camera />
        <disable-keyguard-features />

Remove the privileges you are not interested in.


First, you might want to use these instructions to install your app as a system app on an emulator or rooted device, but it is not necessarily needed. You may also install the app using simple adb install.

After installation, enable admin mode like so:

adb shell dpm set-device-owner com.pixplicity.example/com.pixplicity.example.ExampleDeviceAdminReceiver