Ravi
Ravi

Reputation: 392

How to create a Device Administrator in Android

All of us must have seen under 'Device Administrator' The list of Administrators.

They can perform special tasks.

Any Ideas how to create an app that can become device Admin?

This is just a research, don't take tension!

Upvotes: 3

Views: 10626

Answers (3)

QuartZ
QuartZ

Reputation: 164

You would need 3 thing to do :

  1. add <receiver> to AndroidManifest
  2. make new xml file for <device-admin>
  3. make new .kt file for DeviceAdminReceiver

Example :

in AndroidManifest.xml (inside <activity>, add the code below) :

<receiver
        android:name=".MyDeviceAdminReceiver"
        android:description="@string/app_name"
        android:label="@string/app_name"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/device_owner_receiver" />
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
    </receiver>

in device_owner_receiver.xml, add this code :

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

in MyDeviceAdminReceiver.kt, add the code below :

class MyDeviceAdminReceiver : DeviceAdminReceiver() {
    override fun onEnabled(context: Context, intent: Intent) {
        super.onEnabled(context, intent)
        Toast.makeText(context, "Admin is enabled", Toast.LENGTH_SHORT).show()
    }
}

When you run the app after adding the code at the top, the app will prompt an admin request.

For reference from, developer.android.com.

Upvotes: 1

Asil ARSLAN
Asil ARSLAN

Reputation: 1136

you research more info this documentation or device management policies

Upvotes: 2

Bryan Herbst
Bryan Herbst

Reputation: 67189

The process is described in depth in the Device Administration guide in the Android developer documentation.

At a high level, the steps are:

Once the user has accepted your device as a device administrator, you can perform a limited set of device administration actions in your application.

Upvotes: 11

Related Questions