@Override
public void onDisabled(Context context, Intent intent) {
super.onDisabled(context, intent);
// Lock the device as soon as admin is being disabled
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
devicePolicyManager.lockNow(); // This will lock the device when disabling the admin
}
and in main activity::
// Initialize DevicePolicyManager and ComponentName mDPM = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE); mDeviceAdmin = new ComponentName(this, MyDeviceAdminReceiver.class);
// Check if the app is a device administrator
if (mDPM.isAdminActive(mDeviceAdmin)) {
// If the app is a device admin, display a message and provide a way to disable it
Toast.makeText(this, "App is a device admin", Toast.LENGTH_SHORT).show();
// Provide option to disable
// This would ideally be a button that calls removeDeviceAdmin()
} else {
// If the app is not a device admin, display a message and provide a way to enable it
Toast.makeText(this, "App is not a device admin", Toast.LENGTH_SHORT).show();
// Provide option to enable
// This would ideally be a button that calls enableDeviceAdmin()
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_ENABLE_ADMIN) {
if (resultCode == RESULT_OK) {
// Successfully added as device admin
Toast.makeText(this, "Device admin enabled", Toast.LENGTH_SHORT).show();
} else {
// Failed to add as device admin
Toast.makeText(this, "Failed to enable device admin", Toast.LENGTH_SHORT).show();
}
} else if (requestCode == REQUEST_CODE_REMOVE_ADMIN) {
if (resultCode == RESULT_OK) {
// Successfully removed as device admin
Toast.makeText(this, "Device admin removed", Toast.LENGTH_SHORT).show();
} else {
// Failed to remove device admin
Toast.makeText(this, "Failed to remove device admin", Toast.LENGTH_SHORT).show();
}
}
}
}
i did lock the screen while deactivate is there any system set manual our passowrd