超级管理员(DevicePoliceManager)
来源:互联网 发布:软件版本升级 编辑:程序博客网 时间:2024/05/06 16:31
超级管理员(DevicePoliceManager)
DevicePolicyManager
Public interface for managing policies enforced on a device. Most clients of this class must have published a DeviceAdminReceiver that the user
has currently enabled.
DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);if (dpm.isAdminActive(new ComponentName(context, MyAdmin.class))) { dpm.resetPassword("321", 0); dpm.lockNow();}
DevicePolicyManager中的方法
void lockNow()
Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.boolean resetPassword(String password, int flags)
Force a new device unlock password (the password needed to access the entire device, not for individual accounts) on the user.void wipeData(int flags)
Ask the user date be wiped.boolean isAdminActive(ComponentName who)
Return true if the given administrator component is currently active (enabled) in the system
使用超级管理员DevicePolicyManager的步骤
1. 要写一个类继承DeviceAdminReceiver
java
public class MyAdmin extends DeviceAdminReceiver {
//继承就可以不用重写任何内容
}
在清单文件中配置自定义的类
<receiver android:name=".receiver.MyAdmin" android:description="@string/admin_des" android:label="防卸载" android:permission="android.permission.BIND_DEVICE_ADMIN" > <meta-data android:name="android.app.device_admin" android:resource="@xml/device_admin_sample" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> </intent-filter></receiver>
完成第二步中所需的meta-data。在res下新建一个xml文件,device_admin_sample.xml
<device-admin xmlns:android="http://schemas.android.com/apk/res/android"> <uses-policies> <limit-password /> <watch-login /> <reset-password /> <force-lock /> <wipe-data /> <expire-password /> <encrypted-storage /> <disable-camera /> </uses-policies></device-admin>
经过上面的三步使用后仍报错,这是因为对于超级管理员,用户必须在手机的应用程序-设备管理员中激活我们的程序才能使用,但是对于一般的人不知道要这样激活。
所以我们要在自己的程序中提供一个按钮让用户点击就能进入这个激活超级管理员的Activity
这里可以通过下面的方式来启动这个激活超级管理员的Activity
// 激活设备超级管理员public void zouni(View view) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); // 初始化要激活的组件 ComponentName mDeviceAdminSample = new ComponentName(mContext, MyAdmin.class); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "激活可以防止随意卸载应用"); startActivity(intent);}
一旦程序有了管理员权限程序就不能卸载了,要想卸载必须在手机上取消该程序的超级管理员,以后如果要防止程序的卸载可以通过这种超级管理员的方式。
- 邮箱 :charon.chui@gmail.com
- Good Luck!
- 超级管理员(DevicePoliceManager)
- 忘记mysql超级管理员密码
- 超级管理员不见了的解决方案!
- 做Windows7的超级管理员
- ubuntu -超级管理员root 登录
- 修改超级管理员administrator用户名
- ubuntu -超级管理员root 登录
- ubuntu -超级管理员root 登录
- Android设备超级管理员
- 获得超级管理员的权限
- window超级管理员开启
- Django创建超级管理员
- Ubuntu -超级管理员root 登录
- 【zookeeper】ACL super 超级管理员
- win10 家庭版cmd命令打开超级管理员和关闭超级管理员
- 忘记xp系统超级管理员密码
- ubuntu使用超级管理员root登录
- Win7_家庭版 开启超级管理员账户
- android 截图,视频录制命令 screencap screenrecord screenshot
- UDT协议详解
- Widget简介
- 用GDB调试程序(六)
- 安全退出应用程序
- 超级管理员(DevicePoliceManager)
- 用GDB调试程序(七)
- 程序的启动、卸载和分享
- AWS旧金山云技术大会抢先看:云已成为“新常态”
- TD切换的步骤
- 黑马程序员 异常
- UNIX thread编程(适用于iOS)
- 代码混淆
- Writing Template (April 2015)