热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

安卓ApiDemos学习app/DeviceAdmin/DeviceAdminSample

首先是启动和关闭ActiveAdmin启动ActiveAdminIntentintentnewIntent(DevicePolicyManager.ACTION_ADD_DEVI

首先是启动和关闭ActiveAdmin

启动ActiveAdmin

Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mDeviceAdminSample);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"Additional text explaining why this needs to be added.");
startActivityForResult(intent, RESULT_ENABLE);


向Intent中设置DevicePolicyManager.EXTRA_DEVICE_ADMIN,本例设置了一个ComponentName

mDeviceAdminSample = new ComponentName(Controller.this, DeviceAdminSample.class);设置EXTRA_ADD_EXPLANATION的文字会表示在权限确认画面上,如下图



删除ActiveAdmin

mDPM.removeActiveAdmin(mDeviceAdminSample);

设置密码相关配置。首先要确定当前activity是否已经启动了AdminActive模式

如果是的话,利用DevicePolicyManager的方法,设置密码配置

boolean active = mDPM.isAdminActive(mDeviceAdminSample);if (active) {mDPM.setPasswordQuality(mDeviceAdminSample, pwQuality);mDPM.setPasswordMinimumLength(mDeviceAdminSample, pwLength);mDPM.setMaximumFailedPasswordsForWipe(mDeviceAdminSample, maxFailedPw);}更改屏幕锁定password需要启动系统画面

Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
Restpassword方法中,首先判定用户是否是管理员。

if (mAM.isUserAMonkey()) {// Don't trust monkeys to do the right thing!AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);builder.setMessage("You can't reset my password because you are a monkey!");builder.setPositiveButton("I admit defeat", null);builder.show();return;}如果是,则重置密码

mDPM.resetPassword(mPassword.getText().toString(),DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);






推荐阅读
author-avatar
xinweiss
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有