android添加超级管理权限

1,配置清单文件.注册广播

!--*****************************************超级管理员注册******************-->
        <receiver
            android:name=".AdminReceiver"
            android:description="@string/sample_device_admin_description"
            android:label="@string/sample_device_admin"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin_sample" />

            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>
        </receiver>
2,看着清单文件来,缺什么加什么

  1)需要一个广播接收者,可直接继承,空着就OK

package steaywengwu.android.com.myapplication;

import android.app.admin.DeviceAdminReceiver;

/**
 * Created by steaywengwu on 2017/2/24.
 * 超级管理员权限
 */
public class AdminReceiver extends DeviceAdminReceiver {
}
  2)添加 xml/device_admin_sample.xml文件

<device-admin xmlns: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>

package steaywengwu.android.com.myapplication;

import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * 超级管理员
 * 设置>安全>设备管理器>激活
 */
public class Main3Activity extends AppCompatActivity {

    private DevicePolicyManager dpm;
    private Button button;
    private ComponentName componentName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
        button = (Button) findViewById(R.id.button);
        componentName = new ComponentName(this,AdminReceiver.class);
    }

    public void onclick(View view) {
        if (dpm.isAdminActive(componentName)) {//判断超级管理员是否已激活
            dpm.lockNow();//锁屏
        } else {
            activeAdmin();//跳转激活页面,让用户激活,
        }

    }

    /*
    激活管理员页面
     */
    public void activeAdmin() {
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                componentName);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                "请激活超级管理员");
        startActivity(intent);
    }
}
超级管理员权限APP,手动是删不掉的,必须要先手动移除手机超级超级管理员,例如:设置>安全>设备管理器....然后移除你添加的超级管理员

//dpm.wipeData(0);//擦出数据功能

//dpm.removeActiveAdmin(componentName);//移除超级管理员操作























  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值