The activity class must be an inner class, and the outter class must extend DeviceAdminReceiver
public class adminActivity extends DeviceAdminReceiver { public static class Controller extends Activity { DevicePolicyManager mDPM; ComponentName mDeviceAdminSample; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE); mDeviceAdminSample = new ComponentName(Controller.this, adminActivity.class); } } }
To lock the device, write the code if you use to lock
if (active) { mDPM.lockNow(); }
If DeviceAdmin is enabled, the phone will be locked. To enable the device administrator, the DevicePolicyManager intent is called and it must be enabled by the user.
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
adithi Mar 26 2018-11-11T00: 00Z
source share