/**********************************************************************
* 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();
}
}

最新文章

  1. C#知识点总结系列:C# 数据结构
  2. SQL server 常用语句
  3. MyBatis与Spring整合
  4. runtime 运行机制
  5. .net 时间戳和日期互转 【转】http://www.cnblogs.com/zhuiyi/p/5307540.html
  6. Docker仓库管理
  7. 基于OpenMP的矩阵乘法实现及效率提升分析
  8. 《Python 学习手册4th》 第九章 元组、文件及其他
  9. IOS 保存图片至相册
  10. Do not go gentle into that good night
  11. 0.搭建myeclipse开发环境
  12. Android中让多个线程顺序执行探究
  13. cocos 游戏开发 (第一天作业)
  14. Android中的几个基本常用控件
  15. 51nod 1081 子段求和(线段树 | 树状数组 | 前缀和)
  16. [MySQL TroubleShooting] 服务启动报错
  17. Tomcat 服务器安装 SSL证书,实现 HTTP 自动跳转 HTTPS
  18. ubuntu卸载opencv并重装opencv3.0.0
  19. android:ListView bbs Demo
  20. 《Pro SQL Server Internals, 2nd edition》中CHAPTER 7 Designing and Tuning the Indexes中的Clustered Index Design Considerations一节(译)

热门文章

  1. Nginx隐藏版本号操作
  2. 把旧系统迁移到.Net Core 2.0 日记(4) - 使用EF+Mysql
  3. Java 正则校验整数,且只能是非0开头
  4. python 自然语言处理(二)____获得文本语料和词汇资源
  5. Spring Boot 如何极简入门?
  6. java⑨
  7. 1.DNS基础及域名系统架构
  8. 查找xml中的接口名及涉及表名并输出
  9. [Leetcode 739]*还有几天会升温 Daily Temperatures
  10. Iterator 与ListIterator的区别