How to create a Device Administrator in Android
Asked Answered
U

3

3

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!

Utile answered 7/4, 2015 at 14:24 Comment(0)
D
11

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.

Dissipation answered 7/4, 2015 at 14:33 Comment(2)
Thanks sir. I'll try, then inform you.Utile
For what it's worth, a more detailed article on how to create a basic device administrator (with code and screen-shots) can be found here: androidadministrator.com/?p=82Celebrity
T
2

you research more info this documentation or device management policies

Trumaine answered 7/4, 2015 at 14:49 Comment(0)
V
1

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.

Vincenz answered 3/6, 2021 at 5:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.