android 一键锁屏
来源:互联网 发布:印刷厂排版软件 编辑:程序博客网 时间:2024/06/01 22:13
清单文件加入一个广播接收器
<receiver android:name=".receiver.LockScreenReceiver"> <meta-data android:name="android.app.device_admin" android:resource="@xml/lock_screen" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" /> </intent-filter></receiver>
上面名为lock_screen的xml的引用需要在xml文件夹下建一个文件,里面内容为
<?xml version="1.0" encoding="utf-8"?><device-admin xmlns:android="http://schemas.android.com/apk/res/android"> <uses-policies> <force-lock/> </uses-policies></device-admin>广播接收器内容public class LockScreenReceiver extends DeviceAdminReceiver { @Override public void onEnabled(Context context, Intent intent) { super.onEnabled(context, intent); ToastUtil.toastShort("已获得设备管理者权限"); } @Override public void onDisabled(Context context, Intent intent) { super.onDisabled(context, intent); ToastUtil.toastShort("取消了设备管理者权限"); }}然后开始处理activity中的内容首先初始化需要的对象使用startActivityForResult是为了改变下获取状态DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);ComponentName cn = new ComponentName(this, LockScreenReceiver.class);通过dpm.isAdminActive(cn)方法判断是否获取设备管理者权限以下方法用来获得设备管理者权限
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,cn);startActivityForResult(intent,1);@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(dpm.isAdminActive(cn))admin_station.setText("已获得权限"); else admin_station.setText("未获得权限");}取消管理员权限dpm.removeActiveAdmin(cn);
阅读全文
0 0
- Android笔记:android一键锁屏
- android 一键锁屏
- android 一键锁屏
- Android 设备管理员-android 一键锁屏
- Android应用开发:一键锁屏
- Android一键锁屏程序实例
- android 一键锁屏(二)
- android一键锁屏代码
- Android一键锁屏开发全过程
- Android一键锁屏开发全过程
- android 一键锁屏 开发
- Android一键锁屏程序实例
- android实现一键锁屏
- Android一键锁屏的例子
- Android的一键锁屏
- Android一键锁屏程序实例
- Android 一键锁屏实现
- Android一键锁屏的实现
- mySQL存储千万条数据
- Java操作文件输出为字符串以及字符串输出为文件
- python短网址转换
- 玩转Android之数据库框架greenDAO3.0使用指南
- TCP协议详解
- android 一键锁屏
- [LeetCode] 206-Reverse Linked List
- linux命令的使用
- LSMW、BDC、CATT 区别
- 备忘2017年布尔教育燕十三php视频教
- leetCode--same-tree
- (3)Java环境变量设置和JDK的安装
- 微信小程序开发系列——2. 开发者工具以及开发框架简介
- Python 字符处理方法:str, repr区别