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

Android动态添加Device Admin权限的更多相关文章

  1. Android 动态添加Spinner(.java文件内实现) 实现 改变spinner 内文字属性

    动态添加spinner 控件 Spinner s = new Spinner(this); String []items={"自己定义的要显示的数组"}; my_SpinnerAd ...

  2. Android动态添加和移除布局

    package com.hyang.administrator.studentproject; import android.os.Bundle; import android.support.v7. ...

  3. android动态添加TextView或者ImageView

    动态添加 text1=new TextView(this); text1.setText("动态添加"); ((LinearLayout) this.findViewById(R. ...

  4. Android -- 动态添加布局

    在做项目的时候,遇到了scrollView与listView结合的使用,导致了滑动的混乱,但是有一个办法可以解决掉这个问题,就是手写listView的高度,还有另外一种方法,传送门:<Andro ...

  5. Android动态添加碎片

    我们编写一个能够用过按钮动态更替碎片的APP,首先在主页上显示第一个碎片,点击按钮后可以替换到第二个碎片,或者删除已经替换掉的第二个碎片. 一.MainActivity.java import and ...

  6. Android 动态添加删除ExpandableListView的item的例子

    这个例子可以学习到如下几点: 1.通过自定义Dialog(单独布局的xml文件进行弹出显示) 2.通过menu点击监听添加,删除view中的items 3.点击ExpandableListView中g ...

  7. 关于动态添加iview admin路由以及刷新侧边栏

    在main.js中的mounted中使用router.addRouters()方法后界面上的路由并未刷新. 在注释掉路由跳转的权限限制之后,发现直接在地址栏输入对应路由能够进去,只是侧边栏没有刷新. ...

  8. Android动态添加布局

    //1.利用LayoutInflater的inflate动态加载XML mLinearLayout = (LinearLayout)findViewById(R.id.LinearLayout_ID) ...

  9. Android — — —动态添加碎片

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...

随机推荐

  1. 专题[vjudge] - 数论0.1

    专题[vjudge] - 数论0.1 web-address : https://cn.vjudge.net/contest/176171 A - Mathematically Hard 题意就是定义 ...

  2. Linux 下Qt实现守护进程实例(转)

     原文地址:Linux守护进程的编程方法(含实例) 作者:lingdxuyan 参考文献 Linux信号列表(zz) Linux 守护进程的编程方法 linux上编写守护进程的例程 Linux下后台守 ...

  3. python http 请求 响应 post表单提交

    1. 查看请求 响应情况 print(response.text) print(response.headers) print(response.request.body) print(respons ...

  4. Win10系列:VC++绘制几何图形4

    三角形绘制完成以后,接下来介绍如何给项目添加主入口函数.打开D2DBasicAnimation.h头文件,添加如下的代码定义一个DirectXAppSource类. //定义类DirectXAppSo ...

  5. GFS中文翻译

    Google文件系统 GFS是一个可扩展的分布式文件系统,用于大型的.分布式的.对大量数据进行访问的应用.它运行于廉价的普通硬件上,但可以提供容错功能.它可以给大量的用户提供总体性能较高的服务. 1. ...

  6. 经典面试题sql基础篇-50常用的sql语句(有部分错误)

    Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...

  7. 【转载】Maven中的BOM概念

    1.概述 1.1.什么是 BOM? BOM stands for Bill Of Materials. A BOM is a special kind of POM that is used to c ...

  8. Eclipse界面简介

    下载安装完成后,Eclipse的界面如下: (6)为eclipse的perspective(视图方案)由于安装的是for Java development的eclipse,故视图界面默认 为使用Jav ...

  9. Flatten Nested List Iterator

    Given a nested list of integers, implement an iterator to flatten it. Each element is either an inte ...

  10. httppost core net

    public static string Post(string url, string data, Encoding encoding) { try { HttpWebRequest req = W ...