android – Provides device administrator privileges to install APK by program

Can any one tell me how to enable device administrator privileges? But I can not enable administrator privileges. Pls someone help me what I went wrong with this code

Core business

Protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);

setContentView (R.layout.activity_main);
Toolbar Toolbar = findViewById (;
setSupportActionBar (toolbar);

mDevicePolicyManager = (DevicePolicyManager) getSystemService (Context.DEVICE_POLICY_SERVICE);

boolean isAdmin = false;
if (mDevicePolicyManager.isDeviceOwnerApp (this.getPackageName ())) {
Toast.makeText (getApplicationContext (), "Device Owner", Toast.LENGTH_SHORT) .show ();
isAdmin = true;
} other {
Toast.makeText (getApplicationContext (), "Not the device owner", Toast.LENGTH_SHORT) .show ();