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!
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!
The process is described in depth in the Device Administration guide in the Android developer documentation.
At a high level, the steps are:
DeviceAdminReceiver
and register it in your manifestACTION_ADD_DEVICE_ADMIN
action, and pass your receiver as the DevicePolicyManager.EXTRA_DEVICE_ADMIN,
extra.Once the user has accepted your device as a device administrator, you can perform a limited set of device administration actions in your application.
you research more info this documentation or device management policies
You would need 3 thing to do :
<receiver>
to AndroidManifest<device-admin>
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.
© 2022 - 2024 — McMap. All rights reserved.