Android动态添加Device Admin权限
2024-08-25 22:38:55
/**********************************************************************
* Android动态添加Device Admin权限
* 说明:
* Tony在Android 5上研究的怎么动态添加设备管理员权限。
*
* 2018-6-20 深圳 宝安西乡 曾剑锋
*********************************************************************/ private void enableDeviceAdmin() { ComponentName deviceAdmin = new ComponentName(this, AdminReceiver.class);
DevicePolicyManager mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); // First of all, to access anything you must be device owner
if (mDpm.isDeviceOwnerApp(getPackageName())) { // If not device admin, ask to become one
if (!mDpm.isAdminActive(deviceAdmin) &&
mDpm.isDeviceOwnerApp(getPackageName())) { Log.v(TAG, "Not device admin. Asking device owner to become one."); Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"You need to be a device admin to enable device admin."); startActivity(intent);
} // Device owner and admin : enter device admin
else {
mDpm.setLockTaskPackages(deviceAdmin, new String[]{
getPackageName(), /* PUT OTHER PACKAGE NAMES HERE! /
});
startLockTask();
}
} // Not device owner - can't access anything
else {
Log.v(TAG, "Not device owner");
Toast.makeText(this, "Not device owner", Toast.LENGTH_SHORT).show();
}
}
最新文章
- C#知识点总结系列:C# 数据结构
- SQL server 常用语句
- MyBatis与Spring整合
- runtime 运行机制
- .net 时间戳和日期互转 【转】http://www.cnblogs.com/zhuiyi/p/5307540.html
- Docker仓库管理
- 基于OpenMP的矩阵乘法实现及效率提升分析
- 《Python 学习手册4th》 第九章 元组、文件及其他
- IOS 保存图片至相册
- Do not go gentle into that good night
- 0.搭建myeclipse开发环境
- Android中让多个线程顺序执行探究
- cocos 游戏开发 (第一天作业)
- Android中的几个基本常用控件
- 51nod 1081 子段求和(线段树 | 树状数组 | 前缀和)
- [MySQL TroubleShooting] 服务启动报错
- Tomcat 服务器安装 SSL证书,实现 HTTP 自动跳转 HTTPS
- ubuntu卸载opencv并重装opencv3.0.0
- android:ListView bbs Demo
- 《Pro SQL Server Internals, 2nd edition》中CHAPTER 7 Designing and Tuning the Indexes中的Clustered Index Design Considerations一节(译)
热门文章
- Nginx隐藏版本号操作
- 把旧系统迁移到.Net Core 2.0 日记(4) - 使用EF+Mysql
- Java 正则校验整数,且只能是非0开头
- python 自然语言处理(二)____获得文本语料和词汇资源
- Spring Boot 如何极简入门?
- java⑨
- 1.DNS基础及域名系统架构
- 查找xml中的接口名及涉及表名并输出
- [Leetcode 739]*还有几天会升温 Daily Temperatures
- Iterator 与ListIterator的区别