1.创建一个空的接收者:
package com.example.mobilesafe.receiver;
import android.app.admin.DeviceAdminReceiver;
public class AdminReceiver extends DeviceAdminReceiver{
}
2.配置使用到的超级管理员功能:
在res/xml下新建一个xml文件,填入如下代码(需要什么功能填什么功能,不写全):
<device-adminxmlns: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>
3.在清单文件中配置权限的描述,标题,以及组件全限定名.
<!-- 超级管理员权限 -->
<receiverandroid:name="com.example.mobilesafe.receiver.AdminReceiver"
android:label="@string/sample_device_admin"
android:description="@string/sample_device_admin_description"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-dataandroid:name="android.app.device_admin"
android:resource="@xml/adminpolicy" />
<intent-filter>
<actionandroid:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<!-- 超级管理员权限 -->
4.使用超级管理员的功能:
//清除数据功能
DEVICE_POLICY_SERVICE);
dpm.wipeData(0);
abortBroadcast();
//锁屏功能
DEVICE_POLICY_SERVICE);
dpm.lockNow();
abortBroadcast();
5.弹出激活超级管理员的界面:
new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
new ComponentName(this, AdminReceiver.class);//组件名字
EXTRA_DEVICE_ADMIN, cn);
EXTRA_ADD_EXPLANATION,"可以实现清除数据,锁屏功能");
startActivity(intent);
6.移除超级管理员权限:
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.
DEVICE_POLICY_SERVICE
);
ComponentName cn =
new
ComponentName(
this
, AdminReceiver.
class
);
//组件名字
dpm
.removeActiveAdmin(
cn
);//移除操作
android 超级用户权限 安卓超级管理员权限
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL用户管理与权限管理
MySQL用户管理与权限管理
MySQL MySQL用户管理与权限管理 MySQL用户和权限命令操作 -
android 申请超级管理员权限
作者:dongyx 使用SuperMap iMobile产品需要SuperMap的授权,即获得许可。目前,针对不同的用户和不同的使用场景,SuperMap iMobile提供三种许可方式,分别为试用许可、正式许可、教育许可。一、试用许可 想必有很多同学在使用
android 申请超级管理员权限 SuperMap 许可 iMobile ide -
mysql 给用户添加超级管理员权限 mysql设置管理员权限
mysql 用户管理和权限设置 用户管理 mysql>use mysql; 查看 user 创建 IDENTIFIED 修改 mysql>rename user feng to newuse
mysql 给用户添加超级管理员权限 mysql MySQL 数据库