• Android动态添加Device Admin权限


    /**********************************************************************
     *                 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();
        }
    }
  • 相关阅读:
    第四章 分布式扩展
    第三章 2.性能压测,容量问题
    第三章 1.云部署,打包上传
    MySQL语法大全
    Python随手记
    Python操作Mysql中文乱码问题
    Python基础函数
    破解电信校园网路由限制
    ThinkPHP扩展函数的三个方法
    $_SERVERS预定义变量
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/9204155.html
Copyright © 2020-2023  润新知