Code example for DevicePolicyManager

Methods: isAdminActive, removeActiveAdmin

0
      enableDeviceAdminButton.setText("Enable Device Admin");
 
    } 
    enableDeviceAdminButton.setOnClickListener(new View.OnClickListener() {
      public void onClick(View view) {
        if (mDPM.isAdminActive(mDeviceAdminSample)) {
          // disable here 
          Toast.makeText(WipeConfigActivity.this, "Disabling Device Admin", Toast.LENGTH_LONG).show();
          mDPM.removeActiveAdmin(mDeviceAdminSample);
          if (!mDPM.isAdminActive(mDeviceAdminSample)) {
            enableDeviceAdminButton.setText("Enable Device Admin");
          } 
        } else { 
          // enable here 
 
          Toast.makeText(WipeConfigActivity.this, "Enabling Device Admin", Toast.LENGTH_LONG).show();
          // Launch the activity to have the user enable our admin. 
          Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
          intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
          intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                          "Emergency Wipe needs these Device Admin privileges to monitor failed password attempts and to wipe the device. "); 
          startActivityForResult(intent, RESULT_ENABLE);
 
          if (mDPM.isAdminActive(mDeviceAdminSample)) {
            enableDeviceAdminButton.setText("Disable Device Admin");
          } 
 
        } 
      }