List of usage examples for android.app.admin DevicePolicyManager isAdminActive
public boolean isAdminActive(@NonNull ComponentName admin)
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
final private void switchDeviceAdminStatus(boolean activate) { DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); final ComponentName darcn = new ComponentName(mContext, DevAdmReceiver.class); if (activate && !dpm.isAdminActive(darcn)) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override//from w w w . j ava 2s .co m public void positiveResponse(Context c, Object[] o) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, darcn); startActivityForResult(intent, 10); } @Override public void negativeResponse(Context c, Object[] o) { } }); if (mApplicationRunFirstTime) { mGlblParms.commonDlg.showCommonDialog(false, "I", mContext.getString(R.string.msgs_main_screen_lock_confirm_title), mContext.getString(R.string.msgs_main_screen_lock_confirm_msg), ntfy); } else ntfy.notifyToListener(true, null); } else if (!activate) dpm.removeActiveAdmin(darcn); }